5 Replies Latest reply on Jun 23, 2011 2:21 PM by john_dube

    Script code fails in form (.efm)

    andrew.davidson_2

      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

        • 1. Re: Script code fails in form (.efm)
          john_dube

          Is there any chance that you have multiple DxDesigner processes running?  Some places in the script use dxdApp which is the result of GetObject, where other places in the script use the default application object.  If you had multiple DxD's running, that would explain this behavior.  You can change the script to set dxdApp = Application instead of GetObject, that may fix the problem.

           

          John

          1 of 1 people found this helpful
          • 2. Re: Script code fails in form (.efm)
            andrew.davidson_2

            Hi John,

             

            Your advice led me to close DxD, check processes and restart it. (with and without your suggested change)

            Then when I run the script for the very first time I get an error: Object Required: VD_ALL

            With respect to this line:

             

                  AppendOutput "List Comps","Count " & ActiveView.Query(VDM_COMP, VD_ALL).Count

             

            If I comment it out and restart DxD I get the same error for the next line.

             

                 For Each objComp In dxdapp.ActiveView.Query(VDM_COMP, VD_ALL)

             

            The subsequent times you run it without closing DxD there are no errors, just bad behaviour as previously described.

             

            I used "0" instead of VD_ALL and it got further but failed at the first sheet, unable to find a page number. (which really is there)

            • 3. Re: Script code fails in form (.efm)
              andrew.davidson_2

              OK - I've made some progress, it seems to be related to where you "Dim" the variables. I took out the Dim for dxdapp et all and now it works on the second try (not the first). Is there some kind of guidance on .efm, variables and scope that can help me straighten this out?

              • 4. Re: Script code fails in form (.efm)
                john_dube

                Andrew,

                 

                I suggest you add the "Option Explicit" keyword to the first line of the General Declarations part of the script.

                 

                This will force you to declare each variable, and usually catches typos that lead to unexpected behavior.

                 

                John

                • 5. Re: Script code fails in form (.efm)
                  john_dube

                  The error message you are getting here is probably because you do not have a schematic open, thus the Object Required error message when you use the ActiveView property of the default Application object.

                   

                  John