When you get the document object before you do anything you must ask the license server for authentication.
Set app = GetObject(,"MGCPCB.ExpeditionPCBApplication") 'Use this if you are out of process
Set app = Application 'Use this if you are in process
Set docObj = app.ActiveDocument
Set licenseServer =CreateObject("MGCPCBAutomationLicensing.Application")
Key = docObj.Validate(0)
Set licenseServer = Nothing
docObj.Validate (LicenseToken) 'This makes sure you have an authorized version of Expedition running
This is addressed in PCB Automation Reference Manual (expedition_pcb_auto.pdf).
See "Chapter 1 Examples of PCB Automation > Using Automation Licenses and Document Validation" for more information
I would suggest to create a validation function, such as GetLicensedDoc() introduced in PCB Automation Reference, and get pcbDoc from GetLicensedDoc(app)
It should be shaped like below:
Set app = GetObject(, "MGCPCB.Application") ' or, just "Set app = Application" if you are running the script internally
Set pcbDoc = GetLicensedDoc(app)
' Place your codes here - remove your previous statement of setting pcbDoc
Public Function GetLicensedDoc(app)
... ' Refer to PCB Automation Rererence Manual
Or, place Kendall's code snippet just after your pcbDoc definition, after changing variable 'docObj' to 'pcbDoc' so that it matches to your code.
It should be above the line 72 or below the line 72?
I have called it as main
' Get the application object
'Set pcbApp = GetObject(,"MGCPCB.ExpeditionPCBApplication")
Set pcbApp = GetObject(,"MGCPCB.Application")
' Get the active document
Set pcbDoc = pcbApp.ActiveDocument
then it should call the pcbApp at anywhere right?