1 Reply Latest reply on Dec 12, 2017 12:37 PM by Patrick.Cashman

    Runtime Error during general edit of library with help of a script

    bollenberg

      Dear all,

       

      I would like to edit all cells of a library. Here, every cell should get a part property text.

       

      The following script should do this automatically (subroutines are not shown below):

       

      OptionExplicit

      'global constants (the unitsEnum of all the constants below are in mm)
      Const strFont = "Arial"
      Const realPenWidth = 0.05


      'global variables
      Dim objLibraryApp
      Dim objLibraryDoc
      Dim objCellEditor
      Dim objCellDB
      Dim strCellPartition

      Dim objActivePartition
      Dim objActiveCell

      Dim objActiveCellDoc
      Dim objActiveCellApp

      Dim objLayerText
      Dim objLayerTextToDelete
      Dim objLayerTextCollection
      Dim objUserDraftLayer

      Dim objTextColToFormat
      Dim realHeight

      'add type libraries
      Scripting.AddTypeLibrary("MGCPCB.ExpeditionPCBApplication")

      Scripting.AddTypeLibrary ("MGCPCBLibraries.CellEditorDlg")
      Scripting.AddTypeLibrary("CellEditorAddin.CellEditorDlg")


      Set objLibraryApp = Application                                                                ' Get the Application object 

      Set objLibraryDoc = objLibraryApp.ActiveLibrary                                                ' Get the active document 

      strCellPartition = InputBox("Please enter cell partition!")

      Set objCellEditor = objLibraryDoc.CellEditor                                                        ' Get the Cell Editor 

      Set objCellDB = objCellEditor.ActiveDatabase                                                        ' Get the Cell database for the design 
      ForEach objActivePartitionIn objCellDB.Partitions
          If objActivePartition.Name = strCellPartitionThen                                             ' Focus on Cell-Partition to be edited
              ForEach objActiveCellIn objActivePartition.Cells                                         ' Get Cell-Object from Cell-Collection
                  Set objActiveCellDoc = objActiveCell.Edit()                                             ' Open Cell-Editor
                  Set objActiveCellApp = objActiveCellDoc.Application                                   ' Get Application Object within Cell-Editor
                  objActiveCellApp.Visible = True
                  IfInStr(1,objActiveCellDoc.Name,"CAP",vbTextCompare) Then                           ' Check kind of Cell --> CAP = Capacitor
                      Foreach objUserDraftLayerin objActiveCellDoc.UserLayers                        
                          SelectCase objUserDraftLayer.Name
                          Case"Assembly Items Value"                                                        ' Check UserDraftLayer
                              Call Delete_UserDraftLayer_Text(objUserDraftLayer)                           ' Delete UserDraftLayer-Text
                          Case"Assembly Items Value Top"                                                    ' Check UserDraftLayer
                              Call Delete_UserDraftLayer_Text(objUserDraftLayer)                           ' Delete UserDraftLayer-Text
                              Set objLayerTextCollection = objActiveCellDoc.PutUserLayerTextEx("Value",0,0.5,epcbTextPartProperty,_

                                                      objUserDraftLayer,Nothing,epcbUnitCurrent)   
                              objLayerTextCollection.DisplayCondition = 2
                              Call Set_Text_Format_Top(objLayerTextCollection,0.5)
                          Case"Assembly Items Value Bottom"                                                ' Check UserDraftLayer
                              Call Delete_UserDraftLayer_Text(objUserDraftLayer)                           ' Delete UserDraftLayer-Text
                              Set objLayerTextCollection = objActiveCellDoc.PutUserLayerTextEx("Value",0,0.5,epcbTextPartProperty,_

                                                      objUserDraftLayer,Nothing,epcbUnitCurrent)   
                              objLayerTextCollection.DisplayCondition = 3
                              Call Set_Text_Format_Bottom(objLayerTextCollection,0.5)
                          Case"Assembly Items Voltage"                                                    ' Check UserDraftLayer
                              Call Delete_UserDraftLayer_Text(objUserDraftLayer)                           ' Delete UserDraftLayer-Text
                       Case"Assembly Items Voltage Top"                                                ' Check UserDraftLayer
                              Call Delete_UserDraftLayer_Text(objUserDraftLayer)                           ' Delete UserDraftLayer-Text
                              Set objLayerTextCollection = objActiveCellDoc.PutUserLayerTextEx("Voltage",0,-0.5,epcbTextPartProperty,_

                                                      objUserDraftLayer,Nothing,epcbUnitCurrent) 
                              objLayerTextCollection.DisplayCondition = 2
                              Call Set_Text_Format_Top(objLayerTextCollection,0.5)
                          Case"Assembly Items Voltage Bottom"                                            ' Check UserDraftLayer
                              Call Delete_UserDraftLayer_Text(objUserDraftLayer)                           ' Delete UserDraftLayer-Text
                              Set objLayerTextCollection = objActiveCellDoc.PutUserLayerTextEx("Voltage",0,-0.5,epcbTextPartProperty,_

                                                      objUserDraftLayer,Nothing,epcbUnitCurrent) 
                              objLayerTextCollection.DisplayCondition = 3
                              Call Set_Text_Format_Bottom(objLayerTextCollection,0.5)
                          EndSelect
                      Next
                  Else
                      IfInStr(1,objActiveCellDoc.Name,"RES",vbTextCompare) Then                            ' Check kind of Cell --> RES = Capacitor
                          Foreach objUserDraftLayerin objActiveCellDoc.UserLayers                      
                              SelectCase objUserDraftLayer.Name
                              Case"Assembly Items Value"                                                    ' Check UserDraftLayer
                                  Call Delete_UserDraftLayer_Text(objUserDraftLayer)                       ' Delete UserDraftLayer-Text
                              Case"Assembly Items Value Top"                                                ' Check UserDraftLayer
                                  Call Delete_UserDraftLayer_Text(objUserDraftLayer)                       ' Delete UserDraftLayer-Text
                                  Set objLayerTextCollection = objActiveCellDoc.PutUserLayerTextEx("Value",0,0,epcbTextPartProperty,_

                                                          objUserDraftLayer,Nothing,epcbUnitCurrent) 
                                  objLayerTextCollection.DisplayCondition = 2
                                  Call Set_Text_Format_Top(objLayerTextCollection,0.5)
                              Case"Assembly Items Value Bottom"                                            ' Check UserDraftLayer
                                  Call Delete_UserDraftLayer_Text(objUserDraftLayer)                       ' Delete UserDraftLayer-Text
                                  Set objLayerTextCollection = objActiveCellDoc.PutUserLayerTextEx("Value",0,0,epcbTextPartProperty,_

                                                          objUserDraftLayer,Nothing,epcbUnitCurrent) 
                                  objLayerTextCollection.DisplayCondition = 3
                                  Call Set_Text_Format_Bottom(objLayerTextCollection,0.5)
                              EndSelect
                          Next
                      Else
                          IfInStr(1,objActiveCellDoc.Name,"IND",vbTextCompare) Then                        ' Check kind of Cell --> IND = Capacitor
                              Foreach objUserDraftLayerin objActiveCellDoc.UserLayers                
                                  SelectCase objUserDraftLayer.Name
                                  Case"Assembly Items Value"                                                ' Check UserDraftLayer
                                      Call Delete_UserDraftLayer_Text(objUserDraftLayer)                   ' Delete UserDraftLayer-Text
                                  Case"Assembly Items Value Top"                                            ' Check UserDraftLayer
                                      Call Delete_UserDraftLayer_Text(objUserDraftLayer)                   ' Delete UserDraftLayer-Text
                                      Set objLayerTextCollection = objActiveCellDoc.PutUserLayerTextEx("Value",0,0.5,epcbTextPartProperty,_

                                                             objUserDraftLayer,Nothing,epcbUnitCurrent) 
                                      objLayerTextCollection.DisplayCondition = 2
                                      Call Set_Text_Format_Top(objLayerTextCollection,0.5)
                                  Case"Assembly Items Value Bottom"                                        ' Check UserDraftLayer
                                      Call Delete_UserDraftLayer_Text(objUserDraftLayer)                   ' Delete UserDraftLayer-Text
                                      Set objLayerTextCollection = objActiveCellDoc.PutUserLayerTextEx("Value",0,0.5,epcbTextPartProperty,_

                                                             objUserDraftLayer,Nothing,epcbUnitCurrent)
                                      objLayerTextCollection.DisplayCondition = 3
                                      Call Set_Text_Format_Bottom(objLayerTextCollection,0.5)
                                  Case"Assembly Items Current"                                            ' Check UserDraftLayer
                                      Call Delete_UserDraftLayer_Text(objUserDraftLayer)                   ' Delete UserDraftLayer-Text
                                  Case"Assembly Items Current Top"                                        ' Check UserDraftLayer
                                      Call Delete_UserDraftLayer_Text(objUserDraftLayer)                   ' Delete UserDraftLayer-Text
                                      Set objLayerTextCollection = objActiveCellDoc.PutUserLayerTextEx("Current",0,-0.5,epcbTextPartProperty,_

                                                             objUserDraftLayer,Nothing,epcbUnitCurrent)
                                      objLayerTextCollection.DisplayCondition = 2
                                      Call Set_Text_Format_Top(objLayerTextCollection,0.5)
                                  Case"Assembly Items Current Bottom"                                    ' Check UserDraftLayer
                                      Call Delete_UserDraftLayer_Text(objUserDraftLayer)                   ' Delete UserDraftLayer-Text
                                      Set objLayerTextCollection = objActiveCellDoc.PutUserLayerTextEx("Current",0,-0.5,epcbTextPartProperty,_

                                                             objUserDraftLayer,Nothing,epcbUnitCurrent)
                                      objLayerTextCollection.DisplayCondition = 3
                                      Call Set_Text_Format_Bottom(objLayerTextCollection,0.5)
                                  EndSelect
                              Next
                          Else
                              Foreach objUserDraftLayerin objActiveCellDoc.UserLayers                    
                                  SelectCase objUserDraftLayer.Name
                                  Case"Assembly Items Technology"                                            ' Check UserDraftLayer
                                      Call Delete_UserDraftLayer_Text(objUserDraftLayer)                       ' Delete UserDraftLayer-Text
                                  Case"Assembly Items Technology Top"                                        ' Check UserDraftLayer
                                      Call Delete_UserDraftLayer_Text(objUserDraftLayer)                       ' Delete UserDraftLayer-Text
                                      Set objLayerTextCollection = objActiveCellDoc.PutUserLayerTextEx("Technology",0,0,epcbTextPartProperty,_

                                                             objUserDraftLayer,Nothing,epcbUnitCurrent)
                                      objLayerTextCollection.DisplayCondition = 2
                                      Call Set_Text_Format_Top(objLayerTextCollection,0.5)
                                  Case"Assembly Items Technology Bottom"                                        ' Check UserDraftLayer
                                      Call Delete_UserDraftLayer_Text(objUserDraftLayer)                       ' Delete UserDraftLayer-Text
                                      Set objLayerTextCollection = objActiveCellDoc.PutUserLayerTextEx("Technology",0,0,epcbTextPartProperty,_

                                                             objUserDraftLayer,Nothing,epcbUnitCurrent) 
                                      objLayerTextCollection.DisplayCondition = 3
                                      Call Set_Text_Format_Bottom(objLayerTextCollection,0.5)
                                  EndSelect
                              Next
                          EndIf
                      EndIf
                  EndIf
                  objActiveCellDoc.Save
                  objActiveCellDoc.Close (False)
                  Set objActiveCellApp = Nothing
                  Set objActiveCellDoc = Nothing
              Next
          Else
          EndIf
      Next

      objCellEditor.Quit()
      Set objCellEditor = Nothing

      MsgBox ("Edit of cells within partition --> " & strCellPartition & " <-- is finished")  

       

      If I use this script for a partition with round about fifty cells....there ist no problem. But if I use this scipt for a partion with more than 100 cells, after a certain time of running the script, I get a runtime error and the script is aborted. The script does not always break off at the same location of the script.

      Has anybody an idea?

        • 1. Re: Runtime Error during general edit of library with help of a script
          Patrick.Cashman

          There is a lot going on in this script.  It would be very difficult to read it straight through and keep track of everything that's happening and then follow leads to the problem.

           

          My approach when something is broken like this is:

           

          - make a sample set of data (not my live library, for example)

          - make a copy of the script, and have it open in a text editor alongside your live script

          - remove everything from the live script except what it needs to start up and make a connection to the library

          - Run it against your sample data. See what happens. 

          - Start adding back the pieces of the script from the copy of the script file, 1 by 1, with runs against the sample data at each step.

          - When it quits working, the last you thing you added back in is most likely the problem. If not, it will be near the problem, or may give you some clue as to what the problem is.

           

          There are faster location methods you could use, but scripts often have dependencies that make divide and conquer approaches less useful. Usually brute force is called for to put the script back together and find the problem.