How to call a python toolbox script tool outside Pro

257
1
Jump to solution
02-06-2020 04:29 PM
TheodoreRakel
Occasional Contributor

Someone gave me a python toolbox with a GP script tool in it.  It works fine in Pro, but I'd like to run it from a command window, outside of Pro.  Should this be possible?  I can't figure out how to set the parameters that the tool needs.  I can easily call other GP tools, like GetCount, etc.  I'm running Pro 2.4.3.

0 Kudos
1 Solution

Accepted Solutions
DanPatterson_Retired
MVP Esteemed Contributor

The parameters come from entry into the toolbox.

If you open the script that is associated with the toolbox, you could hardcode the parameters into the script ensuring that you match the parameter number with the appropriate parameter. (probably a GetParameterAsText, or GetParameter or even a sys.argv).

You can even provide them at the end of a script and check to see if __main__ is running, and if so, provide the parameters there

if __name__ == "__main__":
    """optional location for parameters"""
    script = sys.argv[0]
    print("\nRunning... {}\n".format(script))
    arg_1 = "something"
    arg_2 = "something else"
    arg_3 = 3

View solution in original post

0 Kudos
1 Reply
DanPatterson_Retired
MVP Esteemed Contributor

The parameters come from entry into the toolbox.

If you open the script that is associated with the toolbox, you could hardcode the parameters into the script ensuring that you match the parameter number with the appropriate parameter. (probably a GetParameterAsText, or GetParameter or even a sys.argv).

You can even provide them at the end of a script and check to see if __main__ is running, and if so, provide the parameters there

if __name__ == "__main__":
    """optional location for parameters"""
    script = sys.argv[0]
    print("\nRunning... {}\n".format(script))
    arg_1 = "something"
    arg_2 = "something else"
    arg_3 = 3
0 Kudos