Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

My script works fine with a single feature class selected for clip_fc = arcpy.GetParameter(0) .

However when I set clip_fc to MultiValue in the script properties and then select several feature classes, I get an error "Parameters are not valid.".

Can anyone show me where I am going wrong?

import arcpy
import os.path
from arcpy import env

arcpy.env.workspace = r"C:\GIS Home\project_1\clipshps\Combined_mf.gdb"
arcpy.env.overwriteOutput = True
clip_fc = arcpy.GetParameter(0)
clip_name = str(clip_fc)
output_dir = r"C:\GIS Home\project_1\clipshps\outputs_clip"

for fds in arcpy.ListDatasets():
    for fc in arcpy.ListFeatureClasses('','',fds):
        out = os.path.join(output_dir, fc + "_" + clip_name[40:] + "_clip.shp")
        arcpy.Clip_analysis(fc, clip_fc, out, "")
share|improve this question
1  
Could you put up the script with fc_list in it to see how you're using it? –  om_henners Oct 11 '12 at 16:04
    
hi @om_henners Sorry I corrected my question, should make more sense now. –  Matt Oct 11 '12 at 17:39
    
Related: gis.stackexchange.com/questions/9406/… –  Roy Oct 11 '12 at 17:51

1 Answer 1

up vote 15 down vote accepted

You need to loop through your inputs. Multivalue is semicolon delimited. Split on that and loop through them. (AddMessages to show how the fcs are presented)

import arcpy

ins = arcpy.GetParameterAsText(0)
arcpy.AddMessage(ins)

for fc in ins.split(';'):
    arcpy.AddMessage(fc)
    arcpy.Clip_analysis(fc, clipfeats, out)

Though I'm not entirely sure of your workflow. You're passing in multiple features to clip on, but also iterating through multiple features in a GDB? You'll have to take the logic I placed above and figure out what combination of inputs you want (1 or many FCs inside a GDB + 1 or many inputs to your tool)

EDIT ...Based on your comment you want many feature classes clipped by many feature class. Try this mash up of code based on yours and mine:

import arcpy, os

ins = arcpy.GetParameterAsText(0)
arcpy.AddMessage(ins)

arcpy.env.workspace = r"C:\GIS Home\project_1\clipshps\Combined_mf.gdb"
output_dir = r"C:\GIS Home\project_1\clipshps\outputs_clip"


for fds in arcpy.ListDatasets():

    # will loop for every featureclass
    for fc in arcpy.ListFeatureClasses('','',fds):            

        # will loop for each input fc from the tool
        for fc_clip in ins.split(';'):
            outName = os.path.join(output_dir, str(os.path.basename(fc)) + "_" + str(os.path.basename(fc_clip)))
            arcpy.Clip_analysis(fc, fc_clip, outName, "")
share|improve this answer
2  
Here is a link to the ESRI Script Tool Parameter Help Files. They offer a code example too. –  Roy Oct 11 '12 at 17:50
    
Thanks @KHibma Looking at your answer I think I am going about this the wrong way. I have a geodatabase containing a number of feature classes, and I want to clip each feature class several times using different shapefiles. –  Matt Oct 11 '12 at 19:17
    
@KHibma tried that and got 'clip1 does not exist or is not supported' –  Matt Oct 11 '12 at 20:54
    
Ummm it works fine for me? only thing I can think is the output dir. You may need to add ".shp" to the end of your outname as its a folder, not a gdb. –  KHibma Oct 11 '12 at 22:57

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.