AnsweredAssumed Answered

Why the script does not work?

Question asked by go73 on Jul 1, 2019
Latest reply on Jul 5, 2019 by pbo

Hi! Help me, please.


Error on "Set compModsColl = vmDoc.ComponentModifications":

"incorrect name or object given as parameter"




Dim app
Set app = GetObject(,"MGCPCB.Application")

Call Document_VariantManager


Public Function GetLicensedDoc(app)
On Error Resume next
Dim key,licenseServer,licenseToken,docObj
Set GetLicensedDoc = Nothing
' collect the active document
Set docObj = app.ActiveDocument
If (Err) Then
Call app.Gui.StatusBarText("No active document: " + Err.Description,epcbStatusFieldError)
Exit Function
End If
' Ask document for the key
key = docObj.Validate(0)
' Get token from license server
Set licenseServer = _
licenseToken = licenseServer.GetToken(key)
Set licenseServer = Nothing
' Ask the document to validate the license token
If (Err) Then
Call app.Gui.StatusBarText("No active document license: " + Err.Description,epcbStatusFieldError)
Exit Function
End If
' everything is OK, return document
Set GetLicensedDoc = docObj
End Function

Sub Document_VariantManager()

Dim docObj,resultMess,VMappObj
Dim compModsColl, compModObj, totalUnplacedComps, pcbCompObj

' collect PCB document object
Set docObj = GetLicensedDoc(app)
If (docObj Is Nothing) Then Exit Sub

' Get the VM application
Set VMappObj = docObj.VariantManagerControl.Control.VariantGUIApplication
If (Err) Then
Call app.Gui.StatusBarText("An error occured while getting VM: " + vbNewLine + Err.Description,epcbStatusFieldError)
Exit Sub
totalUnplacedComps = 0
Set vmDoc = VMappObj.VMDocument
Set compModsColl = vmDoc.ComponentModifications
' Iterate the collection, check if unplaced component
For Each compModObj In compModsColl
If (compModObj.Operation = eVMOperUnplace ) Then
' Find the component in the PCB database and select it
Set pcbCompObj = _
If Not pcbCompObj Is Nothing Then
pcbCompObj.Selected = True
End If
' Increment the count of unplaced components
totalUnplacedComps = totalUnplacedComps + 1
End if
resultMess = "There are " + CStr(totalUnplacedComps) + " unplaced components in the variant design"
' select the unplaced components and fit it on the board

' Update status bar
Call app.Gui.StatusBarText(resultMess,epcbStatusField1)
End If
End Sub

'End of (Declarations)


Thank you.