2 Replies Latest reply on Mar 25, 2013 7:15 AM by olsmir

    How to run a script if more than one PCB file is opened in ExpeditionPCB

    olsmir

      Hello All.

       

      Does anybody know how to have a script operating on one of the several PCB files opened simultaneously? All my scripts have a well-knowned function checking license:

       

      Public Function GetLicensedDoc(appObj)
          On Error Resume next
          Dim key,licenseServer,licenseToken,docObj

          Set GetLicensedDoc = Nothing

          ' collect the active document
          'Set docObj = appObj.ActiveDocument
          ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

          MsgBox docObj.Name, 0, "name of the PCB the script is currently operating"
          ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

          If (Err) Then 
              Call appObj.Gui.StatusBarText("No active document: " + _
                                            Err.Description,epcbStatusFieldError)
              Exit Function
          End If

          ' Ask Expedition’s 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 appObj.Gui.StatusBarText("No active document license: " + _
                                            Err.Description,epcbStatusFieldError)
              Exit Function
          End If

          ' everything is OK, return document
          Set GetLicensedDoc = docObj
      End Function

       

       

      In the main body the above function is called as:

       

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

      Set doc = GetLicensedDoc(app)

       

      After this, I have an access to the doc object.

       

      Now I need to open two PCBs at once (i.e. two instances of ExpeditionPCB).

      I have noticed that my script allways operates on the PCB I have invoked the earliest regardless of what PCB is currently active.

       

      How can I run my script on PCB that is currently active?