i making 1 tool, , want save result of tool in field i've added. want give name field on basis of amenity selection (here i've given data type of amenity string. , added list of values in amenity parameter education, medical, transportation, etc.). if select "education" amenities field name "edu_ic". how can this? i've added code snippet below
def setupvulnerability(): gp = arc.create(9.3) print(sys.version) inputfc = gp.getparameterastext(0) # input feature class print "inputfc:-'%s'" % (inputfc) fields = gp.getparameterastext(1) print "fields:-'%s'" % (fields) fieldlist = fields.split(";") print "fieldlist:-'%s'" % (fieldlist) amenity = gp.getparameterastext(2) print "amen:-'%s'" % (amenity) all_field_names = [f.name f in arcpy.listfields(inputfc)] field_name = none try: field in fieldlist: field_name = field[0:3]+ "_" + "ic" if field_name in all_field_names: continue else : gp.addfield(inputfc , field_name , "float") field_name = none except: raise error.scripterror() if __name__ == '__main__': setupvulnerability()
i believe problem "amenity" variable, receives input user, not referenced when field being added.
something should work:
amenity = gp.getparameterastext(2) if amenity == "education": field_name = amenity[:3] + "_ic" gp.addfield(inputfc, field_name, "float")
Comments
Post a Comment