Extract field values and use as parameter

5345
3
05-19-2011 02:02 PM
KyleGallagher
New Contributor III
I'm using v10 and am I am wanting to extract a field value from a shapefile and use that value as a new parameter in my Python script.  However, there doesn't seem to be an easy way to do this.  There is a ModelBuilder Only tool named Get Field Value, but it can't be used in Python.  You can throw the tool into ModelBuilder, export it to a Python script, and try and use the code, but the following line of code did not work as there was an error opening the toolbox:

arcpy.ImportToolbox("Model Functions")

I'm basically converting my shapefile to a table view, trying to run Get Field Value, and using that value as a parameter.  Any suggestions are greatly appreciated!!

Thanks,
KG
Tags (2)
0 Kudos
3 Replies
ChrisBoyce
New Contributor II
I just did something similar but used a search cursor. I iterated through every row of a single field, then used that to build a definition query with the layer object. Sounds like a cursor might work for you...

Chris.
0 Kudos
KyleGallagher
New Contributor III
I just did something similar but used a search cursor. I iterated through every row of a single field, then used that to build a definition query with the layer object. Sounds like a cursor might work for you...

Chris.


Could you supply the search cursor code that worked for you?  I've seen it Arc 9 but I know it's a little different now with arcpy in Arc 10.

Thanks!
0 Kudos
TerrySilveus
Occasional Contributor III
Here is some cursor code and a way to get the value of a field
        rows = arcpy.SearchCursor(pathAndNameOfShapefile)
        for row in rows:
            valueOfField = row.getValue(fieldName) 
            #do something here with value

        del rows #delete cursor object variable
        del row #delete row object variable

NOTE: pathAndNameOfShapefile and fieldName are set up as string variables if you use the actual path and name put quotes around it - the same goes for field name


You should also check out UpdateCursor and InsertCursor http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//002z0000001q000000.htm
Specifying a query to get a specific set of rows http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/Specifying_a_query_in_Python/002z00000...
Row methods http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//000v000000nv000000.htm
0 Kudos