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"

 

'(Declarations)

 

Dim app
Set app = GetObject(,"MGCPCB.Application")
Scripting.AddTypeLibrary("MGCVARIANTGUI.MGCVariantGUICtrl.1")

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 = _
CreateObject("MGCPCBAutomationLicensing.Application")
licenseToken = licenseServer.GetToken(key)
Set licenseServer = Nothing
' Ask the document to validate the license token
Err.Clear
docObj.Validate(licenseToken)
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
Else
totalUnplacedComps = 0
docObj.UnselectAll
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 = _
docObj.FindComponent(compModObj.Component.Name)
If Not pcbCompObj Is Nothing Then
pcbCompObj.Selected = True
End If
' Increment the count of unplaced components
totalUnplacedComps = totalUnplacedComps + 1
End if
Next
resultMess = "There are " + CStr(totalUnplacedComps) + " unplaced components in the variant design"
' select the unplaced components and fit it on the board
docObj.ActiveViewEx.SetExtentsToSelection

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

'End of (Declarations)

 

Thank you.

Outcomes