6

I'm just trying to set up the parameters in a tool I've built in ArcGIS. What I want to do is read in a feature class or table and get the values in a specific field called "SITE". The field contains a bunch of site names. What I want to do is read in the values of that field and populate them into the 'Value List' tool parameter property

I've been looking at the tool properties and I though I can use the 'Obtained From' property, but it looks like I can only obtain field names, but not that values in the field.

Is there anyway else to do this?

Is there anyways to read in the values from the SITE field and populate it to a value list programmatically?

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Mar 5, 2013 at 22:28

1 Answer 1

7

You're not really supposed to do this, but you could open a cursor in your validator's updateParameters method.

if self.params[0].value and arcpy.Exists(self.params[0].value):
 value_set = set(row.getValue('COL_NAME')
 for row in arcpy.SearchCursor(str(self.params[0].value))))
 self.params[1].filter.list = sorted(value_set)

This will take some feature layer/table from the first parameter and populate the second parameter's dropdown with a list of values in its COL_NAME field.

Note: this will greatly slow down your validator and is highly discouraged.

answered Mar 5, 2013 at 22:45
2
  • 1
    Thanks Jason, I took what you suggested and made some adjustments. I was trying to avoid obtaining values from another parameter, so I set a cursor search in the validator on a feature class to loop through and append the values to a list and just sorted(set(variable)) and returned it to self.paramas[0].filter.list. This worked perfectly with no apparent performance issues. Commented Mar 5, 2013 at 23:14
  • could you explain this a bit more? what needs to be added to the actual python script. Commented Nov 29, 2017 at 0:14

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.