Attach python script to a button

    Table of contents
    No headers

    Version as of 01:34, 15 Jan 2012

    to this version.

    Return to Version archive.

    View current version

    From the ESRI-L mailing list:

    I recently summarized some research to see if a python script could be converted into a .DLL file and called through a button.  While it appears that python cannot be converted to a .DLL, the script can still be run through the use of a button control.  A big shout out to Nobbir Ahmed with ESRI who help me find this solution!

    To run a python script, or any tool or model created and saved in a toolbox, from a button - customize your toolbars, switch to the COMMANDS tab, at the bottom highlight [UIControls] click "New UIControl", select UIButtonControl and click "create and edit".  The VB Editor window opens. Paste the code supplied below, replacing the name of the toolbox AND the name of the tool or script you wish to reference.  Pay close attention to your scripts actual location and name, NOT ITS LABEL.  These can be got by right clicking the tool in Catalog and reviewing the properties.

    Click save in the VB editor and close it.  Navigate back to your customize>COMMANDS>UIControl, and drag the button to a toolbar location. You can rename or change the icon as needed.

    This works well - enjoy.

    Bret.

    Code:

    Private Sub UIButtonControl1_Click()
    
       Dim pGPToolCommand As IGPToolCommandHelper
       Set pGPToolCommand = New GPToolCommandHelper
    
       pGPToolCommand.SetToolByName "C:\gptoolbutton\TEMP_tools.tbx",
    "GDBcreate"
       pGPToolCommand.Invoke Nothing
    
    End Sub
    
        Send feedback