jeudi 11 décembre 2014

can't set up script tool parameters


I'm using arcgis 10.0. I red the ESRI doc to setting up script tools parameters, but I don't succeed at setting them up.


My parameters before (without variable)



#arcpy.env.workspace = r'Z:\Documents\SIG\tests\synthese_tocorrect.gdb'
#pochoir = r'Z:\Documents\SIG\tests\decoupe.shp' #the clip layer with multiple polygons
#outFolder = r'Z:\Documents\SIG\tests\sorties'


My parameters after, with issues :



import arcpy, os
from arcpy import env
inWorkspace = arcpy.GetParamterAsText(0)#Refers to the geodatabase
pochoir = arcpy.GetParamterAsText(1) #Refers to the existing clip layer
outFolder = arcpy.GetParamterAsText(2) #Output folder.
env.workspace = inWorkspace
arcpy.MakeFeatureLayer_management(pochoir, "pochoirlyr") #Create layer to allow for selection
fcList = arcpy.ListFeatureClasses() #the feature class to be clipped by each of the polygon of the clip layer
OIDField = arcpy.Describe("pochoirlyr").OIDFieldName #Get name of OID field

for fc in fcList:
arcpy.MakeFeatureLayer_management(os.path.join(arcpy.env.workspace, fc), "lyr")
pocursor = arcpy.SearchCursor("pochoirlyr")
for porow in pocursor:
sql = '"' + OIDField + '" = ' + str(porow.getValue(OIDField)) #SQL to select one feature
arcpy.SelectLayerByAttribute_management("pochoirlyr", "", sql) #Select polygon feature by OID
arcpy.SelectLayerByLocation_management("lyr","INTERSECT","pochoirlyr") #Select feature layer to be clipped by selected clip feature
if arcpy.Describe("lyr").FIDSet: #Check for selection
out_poly = os.path.join(outFolder, fc + "_" + str(porow.getValue(OIDField))) #Output feature class
arcpy.Clip_analysis(fc, "pochoirlyr", out_poly)
del porow
del pocursor
arcpy.SelectLayerByAttribute_management("pochoirlyr", "CLEAR_SELECTION")
arcpy.Delete_management("lyr")


And in the properties of the script tools :



  • geodatabase : Workspace or Feature Dataset, input, no multivalue...

  • pochoir : shapefile, input, no multivalue...

  • sorties : Folder, output...


But when I choose a different parameter when opening the script tool GUI, it does not work. It does the job with the IDE parameters.


Any help ?





Aucun commentaire:

Enregistrer un commentaire