5 Replies Latest reply on Jun 21, 2017 6:58 PM by kendall_hiles

    Old script load very slow in VX

    eng.same.tan

      First, I did ask someone help me to write a script for me so when I press keyboard and it will automatically load specific scheme that I saved for me.

      And I also can create my own shortcut key for certain option instead to access from the menu.

      But after migrate to VX, when I hit my shortcut key, the scheme under display control took about 2 seconds to load which is slow for me.

      Just wondering is anyone here can help me to review on the script as below is there any wrong on the script that need to update for VX?

      There is no delay time when I used this script in EE7.9.5.

      Really hope someone can help me on this, appreciate and thanks.

       

       

      Below are some examples:

      ' -------------------------------------------------------------------------------

      Option Explicit

      Dim My_App       ' The application

      Dim My_Board     ' The Board

       

      Set My_App = Application

      Set My_Board = My_App.ActiveDocument

      ' Add the new key binding.

       

        keyBindTables.AddKeyBinding "CTRL+SHIFT+Q", "Edit->Modify->Padstack Processor", BindMenu, BindAccelerator

        keyBindTables.AddKeyBinding "CTRL+SHIFT+W", "Route->Assign Net Name", BindMenu, BindAccelerator

       

        keyBindTables.AddKeyBinding "CTRL+SHIFT+A", "run C:\WDIR\Scripts\displaycontrol.vbs ""Loc: ALL_ON""", BindCommand, BindAccelerator

        keyBindTables.AddKeyBinding "CTRL+SHIFT+Z", "run C:\WDIR\Scripts\displaycontrol.vbs ""Loc: ALL_Off""", BindCommand, BindAccelerator

       

        keyBindTables.AddKeyBinding "CTRL+UP", "ms dx=0,0.5", BindCommand, BindAccelerator

        keyBindTables.AddKeyBinding "CTRL+DOWN", "ms dx=0,-0.5", BindCommand, BindAccelerator

      ' -------------------------------------------------------------------------------

       

       

      Scrip for "displaycontrol.vbs":

       

      Option Explicit

       

      Dim scriptArgsObj, pcbAppObj, pcbDocObj, viewsColl, viewObj, schemeStr

       

      Set scriptArgsObj = ScriptHelper.Arguments

      schemeStr = scriptArgsObj.Item(3)

       

      Set pcbAppObj = Application

      Set pcbDocObj = pcbAppObj.ActiveDocument

       

      If ValidateServer(pcbDocObj) = True Then

          Set viewsColl = pcbDocObj.Views(epcbViewDefaultView)

          For Each viewObj in viewsColl

              Call viewObj.DisplayControl.LoadScheme(schemeStr)

              Exit For

          Next

      End If

       

      '==============================================================================

      ' Function that returns a licensed doc object

      '==============================================================================

      Function ValidateServer(doc)

        Dim keyInt

        Dim licenseTokenInt

        Dim licenseServer

       

        'Ask Expedition's document for the key

        keyInt = doc.Validate (0)

       

        'Get license server

        Set licenseServer = CreateObject ("MGCPCBAutomationLicensing.Application")

       

        'Ask the license server for the license token

        licenseTokenInt = licenseServer.GetToken (keyInt)

       

        '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(licenseTokenInt)

        If Err Then

        ValidateServer = False

        Else

        ValidateServer = True

        End If

      End Function

        • 1. Re: Old script load slower in VX
          Patrick.Cashman

          There is nothing in your script to define the application.  Typically there should be 2 lines of code to hook into the running Xpedition session to create the application and document objects.  I use this:

           

          'Hook to Expedition

          Set app = GetObject(, "MGCPCB.ExpeditionPCBApplication" & "." & prog_id)

          Set doc = GetLicensedDoc(app)

           

          With all the VX releases, you have to specify the COM version.  I use the 'prog_id' variable for this, as you see in the example above.  There are several ways to get this value.  I read it directly from the registry, because there is no need to hard-code any version or path information anywhere in the process.  My entire script to do a display control function similar to yours looks like this:

          Option explicit

          dim app

          dim doc

           

           

          Dim objShell, prog_id, regkey, tmp

          Set objShell = CreateObject("WScript.Shell")

           

           

          'get the value of prog_id from the registry

          regkey = "HKEY_LOCAL_MACHINE\SOFTWARE\Classes\MGCPCB.ExpeditionPCBApplication\CurVer\"

          tmp = objShell.RegRead(regkey)

          tmp = mid(tmp,InStrRev(tmp, ".") + 1)

          prog_id = tmp

           

           

          'Hook to Expedition

          Set app = GetObject(, "MGCPCB.ExpeditionPCBApplication" & "." & prog_id)

          Set doc = GetLicensedDoc(app)

           

           

           

           

          If not doc is nothing then

           

            if doc.activeview.DisplayControl.MiscItems(0) = True then

            doc.activeview.DisplayControl.MiscItems(0) = False

            else

            doc.activeview.DisplayControl.MiscItems(0) = True

            End if

           

          End if

           

           

          Set app = Nothing

          Set doc = Nothing

           

           

           

           

          '-------------------------------------------------------------------------

          ' Function that returns a licensed doc object

          '

          ' Returns:

          '   - 'Nothing' if licensing failed .

          '   - A reference to the active document of the application if

          '     licensing succeeded.

          '-------------------------------------------------------------------------

          Public Function GetLicensedDoc(appObj)

              On Error Resume next

              Dim key,licenseServer,licenseToken,docObj

           

           

              Set GetLicensedDoc = Nothing

           

           

              ' collect the active document

              Set docObj = appObj.ActiveDocument

              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

           

           

          I'm not sure how that was running before, as even with 7.9.x I always use a GetObject statement with the application name included in it. Now that it needs the COM version also, I think there's a delay while the scripting engine tries to get the right application to work with.

          • 2. Re: Old script load very slow in VX
            eng.same.tan

            Patrick,

            Thanks for your reply. Since I do not know about script, I just copy and paste to create new vbs to replace my "displaycontrol.vbs", it's seem not working for my shortcut key .

            Well, by default without any modification, Expedition still will load the schemes named "GraphicalSetting[x]" (where x = numbers) when we press "CTRL+ X" (If you saved any schemes with this naming). But it still load very slow which take about 2 second and it is not make sense to me

             

            Is there any other way to switch layers views by press keyboard instead of using this "displaycontrol.vbs" script?

            Is AATK will work more better and faster?

            • 3. Re: Old script load very slow in VX
              matthias.cosaert

              you can bind to the keyin command 'CL x' to switch layers with a key, for example:
              keyBindTables.AddKeyBinding "CTRL+1", "CL 1", BindCommand, BindAccelerator

               

              Or instead of using a display scheme it is also possible to use automation to change the settings in the displaycontrol which should be faster.

              • 4. Re: Old script load very slow in VX
                Patrick.Cashman

                There is complete and detailed information on how to set up your own menus and hotkeys in this thread.

                • 5. Re: Old script load very slow in VX
                  kendall_hiles

                  He is running in process and  Set pcbAppObj = Application and Set My_App = Application are correct.  It is incorrect to use the GetObject for scripts that are in process. When it is in process you do not need to worry about the com versioning either.

                   

                  -kendall