2

I am using arc 10.4.1, I am having trouble adding the environment settings into my script. I want the user to set the environment, without having to hit this button and setting it:

enter image description here

I have attempted:

env.workspace = arcpy.GetParameterAsText(0)

It runs fine, but exports to the folder outside the one I set.

Midavalo
30k11 gold badges53 silver badges108 bronze badges
asked Mar 20, 2017 at 19:39
0

1 Answer 1

5

Here's my script, sets the Environment Workspace based on a folder/geodatabase, and then copies a pre-existing feature class to that workspace (based on the fact that I don't set a location for the output, just a feature class name).

import arcpy
arcpy.env.workspace = arcpy.GetParameter(0)
arcpy.AddMessage(arcpy.env.workspace)
# Copy existing feature class to location specified above
arcpy.CopyFeatures_management(r"D:\GIS\SE\GISSE.gdb\testPoint", "abcd")

Note: I tend to use arcpy.GetParameter() rather than arcpy.GetParameterAsText() for my tool parameters as this allows the objects to be referenced rather than receiving just a string. I only use arcpy.GetParameterAsText() if I specifically require/expect a string, or if an object isn't available. I have tested both in this case, and I get the same result with both.

In your script tool properties, on the Parameters tab, set your Data type to "Workspace" to enable browsing to a folder or geodatabase workspace.

enter image description here

To test, run the tool and browse to or enter a workspace path and hit OK

enter image description here

enter image description here

By browsing to this new location in Catalog window, I can see that the new feature class was created in the workspace specified by user entry in the tool.

enter image description here

answered Mar 21, 2017 at 4:21
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.