Thanks for the super fast answer!
Works great!
Thanks!
Moving along the script, next, i would like for example to Clip some features.
Now, each of the clip parameters can differ at each run of the script (the source layer, the target layer and the output name)
How can I do this? (without definning them as parameters in a toolbox)
Should I use the raw_input again for each parameter?
if so, I can't use the arcpy.env.workspace = r'%s' %CSTFC for the source layer for example,
so how do i define the raw_input result as the in feature for the clip command?
Thanks for any help
Using the raw_input() function is the "non-script tool" way of getting parameters as text when used in combination with the %s (which is a parameter substitution for string, I think?), so I suppose the answer to your question is yes. You can use raw input for each parameter if you want to use this without having to use Arc at all. If you wanted to run a clip process using only user input you can use raw input as much as you want instead of GetParameterAsText(). If you just want to clip all the features in the workspace that is provided and ask the user to also define the clip boundary you could do something like this:
import arcpy, os, sys, traceback
ws = raw_input('Please Copy and Paste Worspace Environment\n')
arcpy.env.workspace = r'%s' % ws
arcpy.env.overwriteOutput = True
# Local variables
folder = 'Clipped_features'
try:
if arcpy.Exists(ws):
arcpy.CreateFolder_management(ws, folder)
clip_feat = raw_input('Copy and paste full path of clip boundary feature\n')
fclist = arcpy.ListFeatureClasses()
for fc in fclist:
arcpy.Clip_analysis(fc, clip_feat, os.path.join(folder, fc))
print 'Clipped: ' + fc
else:
print 'Workspace does not exist or is not supported'
I use the raw input function all the time for when I am too lazy to make script tools. It can be a good work around if you do not want to use script tools.If you wanted to add an SQL query for the clip boundary features you could add this to the above script. I do this for queries sometimes too like this:
field = raw_input('type field name')
value = raw_input('type value')
cliplyr = clip_feat.split('.')[0]
query = "%s" = '%s' % (field, value)
arcpy.MakeFeatureLayer_management (clip_feat, cliplyr, query) # sub cliplyr in the clip tool if query is used
If I type City for the field and Chicago (assuming these are valid field names and unique values) for the value it will work just like any other query and read as:"City" = 'Chicago'