4

Using the Validator in the ArcGIS 10.1 tool GUI, can I loop through and List feature classes from a workspace type parameter (ie a file geodatabase) and then go on and list the values of a field in a feature class from that list? I'm trying to do this:

if self.params[0].value and arcpy.Exists(self.params[0].value):
 for fc in arcpy.ListFeatureClasses(self.params[0].value):
 if fc == "TestFC":
 value_set = set(row.getValue("SITE")
 for row in arcpy.SearchCursor(str(self.params[0].value)))
 self.params[1].filter.list = sorted(value_set)

where param[0] is a workspace type parameter where the user chooses a geodatabase. param[1] will be a string type parameter set as a value list. I want to read in a setted value list from all the values in the 'SITE' field so the user can choose which site the tool will further process on.

Maybe in other words:

  1. User opens tool
  2. User chooses a file geodatabase as the first parameter
  3. User will then choose a SITE from the list derived from the first parameters testfc feature class, 'SITE' field
PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Apr 23, 2013 at 15:55

1 Answer 1

3

This should be possible but your usage of ListFeatureClasses and SearchCursor is incorrect:

  • ListFeatureClasses requires you to set arcpy.env.workspace first. Its arguments are optional, but the first is a wildcard, not a workspace.
  • SearchCursor's first argument is a table or feature class, not a workspace.

That being said, I wouldn't really recommend using tool validation for this if you can avoid it. It will be slow, and really doesn't add much value compared to simply exposing a SQL Expression parameter obtained from another parameter (this doesn't require any tool validation code). See How to populate SQL options for parameter in ArcGIS 10 tool?

answered Apr 23, 2013 at 16:40
1
  • Thanks blah238. I went back and noticed I was entering wrong arguments. I wrote a script before this using the validation in the same kind of way and it worked well. In this case, you were right. It slowed the loading sequence and processing time significantly. I've tried a whole different approach with my script now. Thanks, Commented Apr 25, 2013 at 15:22

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.