perezstr

Script in ArcToolbox:Inspect table/fc/input1 for fields to be used in input2

Discussion created by perezstr on Nov 23, 2010
Latest reply on Nov 23, 2010 by csny490
Glad to be using the new python subforum!

I want to have my python script look at the fields (gp.listfields maybe) and create a dropdown input box for the user to be able to see that the script can see what fields are in the input1.

Use case is I want to get a list of unique values in a field.  I know I can have the user open the table/fc and discover the field and then type it into an input box but that isn't cool.  I imagine it will have to be a two part script..like do a gp.listfields then ask the user to pick the field then start running again.  Here is my code now.

import os, string, sys, win32gui
import arcgisscripting
gp = arcgisscripting.create(9.3)
gp.workspace = "c:\\"

infc = sys.argv[1]
field = sys.argv[2]

for fld in gp.listfields(infc):
    pass
    #stuck here!
   

try:
    rowlist = []###unique values in user specified column
    sc = gp.searchcursor(infc)#user defined
    row = sc.next()
    while row:
        altline = row.getvalue(field)#user defined
        #print altline
        if str(altline) not in rowlist:
            rowlist.append(str(altline))
        row = sc.next()
    del row
    del altline

except:
    print gp.getmessages()

Outcomes