Select to view content in your preferred language

new to python...

713
4
03-22-2013 09:43 AM
ChrisJ
by
Deactivated User
new to python AND new to arcgis 9.3, coming from mapbasic background.

I'm learning some python for scripting in 9.3, and come up with this:

import arcgisscripting

# create the geoprocessor object
gp = arcgisscripting.create(9.3)

gp.workspace = "I:\PDtest"

# process
gp.PointDistance_analysis("stores.shp", "competitors.shp", "output.dbf", "1000 meters")

...it runs fine, but, what if I wanted to have a user input the names etc into a text box before this continued?  like so:

workspace_entry = raw_input('please enter path to workspace')
layer1 = raw_input('please enter first layer')
layer2 = raw_input('please enter second layer')

or something like that; it crashes when I try, but still very new to all of this...

thanks,

cj
Tags (2)
0 Kudos
4 Replies
BruceNielsen
Frequent Contributor
The answer depends on if you are running this script standalone, or as a tool from ArcMap. As a standalone, the raw_input should work:
import arcgisscripting

# create the geoprocessor object
gp = arcgisscripting.create(9.3)

gp.workspace = raw_input('please enter path to workspace')

# process
layer1 = raw_input('please enter first layer')
layer2 = raw_input('please enter second layer')
gp.PointDistance_analysis(layer1, layer2, "output.dbf", "1000 meters")

etc.


If this script is being run as a tool from ArcMap, you will need to set up tool parameters, then use the appropriate gp command to insert them into the script:
import arcgisscripting

# create the geoprocessor object
gp = arcgisscripting.create(9.3)

gp.workspace = gp.getparameterastext(0)

# process
layer1 = gp.getparameterastext(1)
layer2 = gp.getparameterastext(2)
gp.PointDistance_analysis(layer1, layer2, "output.dbf", "1000 meters")

etc.


FYI, if you're going to use backslashes in a hard-coded path name, either designate it as a raw string (r"I:\PDtest") or use a double backslash ("I:\\PDtest"). Using a forwardslash ("I:/PDtest") is acceptable as well.
0 Kudos
ChrisJ
by
Deactivated User
bruce thanks very much for your dual explanation; I'll give this a try and see how it goes...
0 Kudos
curtvprice
MVP Alum
Chris, I recommend this *free* online course to get you started right:


'>Python for Everyone Using ArcGIS 10.1
0 Kudos
ChrisJ
by
Deactivated User
thanks very much cvp, will check this out....
0 Kudos