3 Replies Latest reply on Jun 22, 2017 6:35 AM by cornelia.goller

    Xpedition PCB what's wrong - script run with error (vb-ais)

    cornelia.goller

      Hello,

      when i "call" the script in the Epediton PCB with "run ...."     it works korrekt (without an error)

      when i call the script via the implemented menu (usermenu) it dont works:

        Loading failed: ....vbs  Laufzeitfehler in MS VBScript4240

      It is the same script. (see in the follow)

      must i insert an "wait.." ? if yes - how can i do this?

       

       

      ' This is a template script for a script that will get
      ' a running instance of the server with a job already open
      ' There is no error checking of the pcbDoc or pcbApp objects

      Option Explicit

      ' Get the application object
      Dim pcbApp
      Set pcbApp = GetObject(,"MGCPCB.Application")

      ' Get the active document
      Dim pcbDoc
      Set pcbDoc = pcbApp.ActiveDocument

      ' License the document
      ValidateServer(pcbDoc)

      pcbApp.Gui.SuppressTrivialDialogs=true

      ' add a reference to the MGCPCB type library in order to use enums
      Scripting.AddTypeLibrary("MGCPCB.Application")

      ' Invoke Idf Import dialog
      pcbApp.Gui.ProcessCommand("File->Export->General Interfaces")

      ' Get a reference to this dialog
      dim dlgObj
      Set dlgObj = pcbApp.Gui.FindDialog("General InterfacesF")

      ' Create a replay file to fill out the controls in the form.
      Dim fso
      Set fso = CreateObject("Scripting.FileSystemObject")

      Dim file
      Set file = fso.CreateTextFile("C:\Temp\FillAIS.l", True)

      file.WriteLine ("* Version 1.0: ")
      file.WriteLine ("d 0 992 0 993 x 1728 1 0 1")
      file.WriteLine ("d 0 992 0 993 x 1730 1 0 1")
      file.WriteLine ("d 0 992 0 1 b 8")
      file.WriteLine ("a 0 1")
      file.WriteLine ("a 0 1")
      file.WriteLine ("a 0 1")

      ' Run the replay file
      pcbDoc.ReplayFile("C:\Temp\FillAIS.l")

      'MsgBox "Pause"

      ' Press the OK button
      Set dlgObj = pcbApp.Gui.FindDialog("Expedition PCB")
      dim buttonObj
      Set buttonObj = dlgObj.FindButton("OK")

      buttonObj.Click
      pcbApp.Gui.SuppressTrivialDialogs=false

      'Set fso    = Nothing
      'Set pcbApp    = Nothing

      ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
      'Local functions

      Private Function ValidateServer(doc)
         
          dim key, licenseServer, licenseToken

          ' Ask Expedition’s document for the key
          key = doc.Validate(0)

          ' Get license server
          Set licenseServer = CreateObject("MGCPCBAutomationLicensing.Application")

          ' Ask the license server for the license token
          licenseToken = licenseServer.GetToken(key)

          ' Release license server
          Set licenseServer = nothing

          ' Turn off error messages.  Validate may fail if the token is incorrect
          On Error Resume Next
          Err.Clear

          ' Ask the document to validate the license token
          doc.Validate(licenseToken)
          If Err Then
              ValidateServer = 0   
          Else
              ValidateServer = 1
          End If

       

      End Function