2 Replies Latest reply on Nov 28, 2015 6:51 AM by ivanhooi

    Key Binding on PlaceMode, RouteMode and Draw Mode.

    ivanhooi

      Hi All,

       

      I have tried out the example of key binding example, but I'm trying to bind those function which is not listing in the menu like place/route/draw mode and even hover snap.

      Anyone please help to enlighten me?

       

      Here are the examples of the key binding I'm using.

       

      BindMenu = 0

      BindAccelerator = 1

      BindCommand = 1

       

      Scripting.AddTypeLibrary("MGCSDD.KeyBindings")

      Dim keyBindTables

      Set keyBindTables = Gui.Bindings("Document")

       

      keyBindTables.AddKeyBinding "Tab", "Edit->CircuitMoveCopy", BindMenu, BindAccelerator

      keyBindTables.AddKeyBinding "Alt+G", "Place->Group", BindMenu, BindAccelerator

        • 1. Re: Key Binding on PlaceMode, RouteMode and Draw Mode.
          matthias.cosaert

          Hi,

           

          You can run those commands by using the command ID (Call pcbAppObj.Gui.ProcessCommand(CommandId,True))
          It seems though that .AddKeyBinding does not support running a commandID but you can bind to a script that runs Gui.processcommand(..)

           

          Script to toggle hover snap mode:

           

          '-------------------------------------------------------------------------
          'Internal script connect to expedition pcb and get pcbAppObj and pcbDocObj
          '-------------------------------------------------------------------------
          Dim pcbAppObj                'Application object
          Dim pcbDocObj                'Document object
          Scripting.AddTypeLibrary("MGCPCB.ExpeditionPCBApplication")

          ' Get the application object.
          Set pcbAppObj = Application

          ' Get the active document
          Set pcbDocObj = pcbAppObj.ActiveDocument

          ' License the document
          ValidateServer(pcbDocObj)
          '-------------------------------------------------------------------------

           

          'call GetToolbarCommandId("Snap",5) 'get command id to enter in code

          Call pcbAppObj.Gui.ProcessCommand(59417,True)

           

          '=============================================================
          Function GetToolbarCommandId(ToolbarName,ButtonLocation)
          '=============================================================

          Dim stdToolBar : Set stdToolBar = Gui.CommandBars(ToolbarName)

                if stdToolBar is nothing then
                    Msgbox "Could not find '" & ToolbarName & "' toolbar.",0+16
                else

                    dim stdTBCtrls : Set stdTBCtrls = stdToolBar.Controls

                    if stdTBCtrls is nothing then
                         Msgbox "Error getting controls on '" & ToolbarName & "' toolbar.",0+16
                    else

                         for i = 1 to stdTBCtrls.count

                              if i = ButtonLocation then
                                   msgbox stdTBCtrls.item(i).id
                                   exit for
                              end if

                         next
                    end if
                end if

          end function
          '=============================================================

           

          '=============================================================
          ' Validate server function
          '=============================================================
          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
          '=============================================================

          1 of 1 people found this helpful