Turning code into a script and parameterizing?

3311
9
Jump to solution
08-21-2015 08:49 AM
TravisLathrop1
New Contributor III

I have python code that I want to turn into a script.

I want the end user to be able to navigate to the feature class the code should be run on.

The code I have currently speaks to a specific feature class and doesn't allow for picking what feature class the code is to be run on.

How do I change my code so I can have the parameters in the script allow the end user to pick what feature class the code should be run on?

This is the piece of code I need to change to allow the end user pick the feature class.. enter image description here

What do I need to change in my code to allow for the peramiters I set up in the script to replace this line of code? I need fc to equal the input the end user selects not a specific feature class as the code currently stands.

I changed that line of code to fc = arcpy.GetParameterAsText(0) and set up parameters in my script dialogue but it errors out on me every time.  Code works fine w/out the "getparametersastext" addition mentioned above.

0 Kudos
1 Solution

Accepted Solutions
WesMiller
Regular Contributor III
9 Replies
FreddieGibson
Occasional Contributor III

How are you wanting your user to execute your code? Do you want them to execute it via a Script tool within the ArcGIS Desktop application? Are you wanting them to paste your code into the python window? Are you wanting to execute it standalone from a DOS prompt or python IDE?

0 Kudos
WesMiller
Regular Contributor III

If your tying your script to a tool box its pretty simple

http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00150000001r000000.htm

DanPatterson_Retired
MVP Emeritus

Wes...  you can't use 10.2 links...they go nowhere...it is a known bug, there is a workaround but use 10.3.1 links since (unless there is a difference) they are largely the same.

0 Kudos
WesMiller
Regular Contributor III

Dan Patterson how do i find 10.3.1 links i searched "add python script to toolbox 10.3.1" but it doesn't return any results for 10.3.1 I'm using IE10

0 Kudos
RebeccaStrauch__GISP
MVP Emeritus

The top level help for Python in 10.3 is ​http://desktop.arcgis.com/en/desktop/latest/analyze/python/what-is-python-.htm   

Tools in Toolboxes is discussed Adding a script tool—Help | ArcGIS for Desktop

Travis, can you give a snapshot of how you have the dialog box setup?  also, what is the error you are getting?

WesMiller
Regular Contributor III

Thank you

0 Kudos
TravisLathrop1
New Contributor III

Rebecca thanks for the feedback....below are two snap shots my my dialog box set up. 

Parameters.pngGenearl.png

0 Kudos
DanPatterson_Retired
MVP Emeritus

Comments...

  • Why the command line image?
  • Use relative paths?
  • You have to run the script from within the toolbox... either add the layer to arcmap ( so you can select it) OR navigate to it on disk.

0 Kudos
TravisLathrop1
New Contributor III

Apparently I had a bug in ArcMap. I had to reinstall the software and once I did that the script worked fine.

0 Kudos