AnsweredAssumed Answered

Script code fails in form (.efm)

Question asked by andrew.davidson_2 on Jun 23, 2011
Latest reply on Jun 23, 2011 by john_dube

Hi All,

 

I'm using the code to walk through all the sheets of a design. The exact code fragment is below.

This works fine when I do a run <filename>.vbs

When I put it as code to execute under a button it fails miserably and can't find any components on the sheets.

I can't understand what the difference might be. See the bold text.

 

' Create the DxDesigner objects used later
Set dxdapp = GetObject(,"Viewdraw.Application")
Set dxdview = dxdapp.ActiveView   ' View Object
Set dxddoc = dxdapp.ActiveDocument
Set dxddocs = dxdapp.SchematicSheetDocuments
Set dxdblock = dxdview.ActiveBlock
' Get the name of the top level schematic
sTopBlock = dxdblock.GetName(SHORT_NAME)

Dim aCount, bCount, PageCount, FullPageCount, PageCountArray(), HiddenPageCountArray(),LargestPageNumber
Dim PageTask
'Setup the list of pagenumbers
PageCount = 0
Redim Preserve PageCountArray(PageCount)

     Dim dictPaths, objComp, sPath, sSchematic, sSheet
   


     Set dictPaths = CreateObject("Scripting.Dictionary")
     dictPaths.Add "", sTopBlock
     For Each objComp In dxdapp.DesignComponents("", sTopBlock, "-1", "STD", True)
          If objComp.SymbolBlock.SymbolType = VDB_COMPOSITE Then
               sPath = objComp.GetName(0)
               On Error Resume Next
               sSchematic = objComp.SymbolBlock.GetChildBlock.GetName(0)
               If Err.Number > 0 Then
                    sSchematic = objComp.SymbolBlock.GetName(2)
               End If
               dictPaths.Add sPath, sSchematic
          End If
     Next

 

     ValidData = true

 

     dxddocs.Close
     For Each sPath In dictPaths.Keys
          sSchematic = dictPaths(sPath)
          For Each sSheet In dxddocs.GetAvailableSheets(sSchematic)
               dxdapp.PushPath sTopBlock, sPath, sSheet
               PageCount = PageCount + 1
               Redim Preserve PageCountArray(PageCount)
               AppendOutput "List Comps","Name " & ActiveView.GetName(2)   'This shows the same path/names both ways
               AppendOutput "List Comps","Count " & ActiveView.Query(VDM_COMP, VD_ALL).Count    'This shows the number of components as vbs, 0 as efm

               For Each objComp In dxdapp.ActiveView.Query(VDM_COMP, VD_ALL)
                   AppendOutput "List Comps","found an object" 'The code never gets here as a .efm
                   If objComp.SymbolBlock.IsBorderSymbol Then
                          Set PageAttr = objComp.FindAttribute("page_number")   
                          If PageAttr Is Nothing Then
                                ValidData = False
                                dxdapp.PushPath sTopBlock, sPath, sSheet
                               MsgBox "No page_number found, This is an error." 
                          Else
                               If Not PageAttr.InstanceValue = "" Then
                                      PageCountArray(PageCount) = PageAttr.InstanceValue
                                Else
                                       PageCountArray(PageCount) = PageAttr.Value
                                 End If
                          End If
                 End If
              Next
              dxddocs.Close
          Next
     Next

Outcomes