AnsweredAssumed Answered

How to get field values from every feature, and place them in a comma seperated string?

Question asked by msk05004 on Feb 5, 2016
Latest reply on Feb 8, 2016 by GSCUser85

Hello, I have a modelbuilder tool with an iterator that produces a selection in another feature class each iteration.  I would like to get the value of a field from the records in each selection, and put them in a coma separated string.

 

I have attempted to use an embedded python tool to use a search cursor over these records, but it does not seem to work.  I get a runtime error: cannot open '<<field name>>'

 

Do you have any suggestions as to how to accomplish this?  Would a searchcursor work in an iterator model? Thank you.

 

--

My python tool containing the search cursor.  It works as expected in isolation, but not in the model builder tool.

 

import arcpy
from arcpy import env
env.workspace = arcpy.GetParameterAsText(0) 

##import time
#from datetime import datetime

##current_time=time.strftime("%H:%M:%S")+" "+ time.strftime("%d/%m/%Y")


local_pairlist = "" #list will be populated with pair ids from paths in prevailing direction

#selected features

pathfc      = arcpy.GetParameterAsText(1)  #demand paths in prevailing direction

path_pair_id= str(arcpy.GetParameterAsText(2)) #pair id field


with arcpy.da.SearchCursor(pathfc,(path_pair_id,)) as path_cursor:


                
        newpair=path_row[0] 

        if local_pairlist == "":
            local_pairlist+=newpair
        else:
            local_pairlist+=r","+newpair
       
                
    #--//colection loop--#   

##print "OD Builder Finished!\n\nOutput table="+str(out_name)+"\n\nLocation: " + str(out_path)


arcpy.AddMessage("Subpairs saved!")
arcpy.SetParameter(3, local_pairlist) 

Outcomes