Runtime Error during general edit of library with help of a script
bollenberg Dec 12, 2017 7:01 AMDear 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):
Option Explicit
'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
For Each objActivePartition In objCellDB.Partitions
If objActivePartition.Name = strCellPartition Then ' Focus on Cell-Partition to be edited
For Each objActiveCell In 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
If InStr(1,objActiveCellDoc.Name,"CAP",vbTextCompare) Then ' Check kind of Cell --> CAP = Capacitor
For each objUserDraftLayer in objActiveCellDoc.UserLayers
Select Case 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)
End Select
Next
Else
If InStr(1,objActiveCellDoc.Name,"RES",vbTextCompare) Then ' Check kind of Cell --> RES = Capacitor
For each objUserDraftLayer in objActiveCellDoc.UserLayers
Select Case 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)
End Select
Next
Else
If InStr(1,objActiveCellDoc.Name,"IND",vbTextCompare) Then ' Check kind of Cell --> IND = Capacitor
For each objUserDraftLayer in objActiveCellDoc.UserLayers
Select Case 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)
End Select
Next
Else
For each objUserDraftLayer in objActiveCellDoc.UserLayers
Select Case 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)
End Select
Next
End If
End If
End If
objActiveCellDoc.Save
objActiveCellDoc.Close (False)
Set objActiveCellApp = Nothing
Set objActiveCellDoc = Nothing
Next
Else
End If
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?