Model Builder Iterator to calculate value of field

5961
7
Jump to solution
02-10-2011 09:40 AM
mattstutts
New Contributor II
I don't use ModelBuilder too much and am trying to help someone w/this issue.  I want to step through an attribute table and select each feature (currently trying the Iterate Feature Selection tool w/a group-by ID).  These IDs are a variety of things (some are short strings like 30-11-222, some are GUIDS {A122......} but the field is type String.)

Simply, each time there is a new ID, copy that value and put it into another table that has an empty field called "ID".

This is just a small extract of a larger model, so it's sort of abstracted.  But that's the basic idea of this section.  Can't seem to get it to go.  Originally, it would hang up on the Calculate Field b/c the 'value' coming from the iterator is type variant.  I tried throwing in a 'Calculate Value' tool to change that to a string type and then running the Calculate Field but it doesn't like that either (some sort of syntax error: unexpected EOF while parsing (<string>, line 1).

Attaching a screen shot for now.  Should be easier than this...
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
ChristopherDeRolph
New Contributor III
Apparently this is a bug, but there is a workaround that works.  Here's the email I got from ESRI tech support:


Hi Chris,

I have found bug ID #NIM055433.  This bug recognizes that the Calculate Field tool fails when setting field value to iterator value when iterator uses a text field.  The workaround is to put quotations around the %value%, such as "%value%".  Please try this workaround and let me know the results.

Thanks for your time and patience!

Regards,

Evan B.

View solution in original post

7 Replies
ChristopherDeRolph
New Contributor III
I'm having this same issue Matt.  Did you ever come up with a solution?

Thanks!

Chris
0 Kudos
mattstutts
New Contributor II
Nope.  As usual, my questions go unanswered on this site.  I had completely forgotten about it.
0 Kudos
ChristopherDeRolph
New Contributor III
Apparently this is a bug, but there is a workaround that works.  Here's the email I got from ESRI tech support:


Hi Chris,

I have found bug ID #NIM055433.  This bug recognizes that the Calculate Field tool fails when setting field value to iterator value when iterator uses a text field.  The workaround is to put quotations around the %value%, such as "%value%".  Please try this workaround and let me know the results.

Thanks for your time and patience!

Regards,

Evan B.
by Anonymous User
Not applicable

Thanks! This works and saved me a bunch of time!

0 Kudos
Joseph_Kinyon
Occasional Contributor II

All,

I encountered this same problem in ModelBuilder in ArcGIS Pro 3.0 today ten years later and FYI the workaround still appears to do the job.

 

Joe

0 Kudos
DarrenWiens2
MVP Honored Contributor
This code finds all unique IDs in a feature class, and sticks them into a new table.
import arcpy

input = "H:/GIS_Data/TEMP_GDB.gdb/feattoline" # feature class to iterate
gdb = "H:/GIS_Data/TEMP_GDB.gdb" #gdb or folder for your new table
table = "JunkTable"
tabpath = gdb + "/" + table

arcpy.CreateTable_management(gdb,table)

arcpy.AddField_management(tabpath,"ID","TEXT")

rows = arcpy.SearchCursor(input)

ids = []

for row in rows:
    if row.FID_polyfc not in ids:
        ids.append(row.FID_polyfc)

insrows = arcpy.InsertCursor(tabpath)

for id in ids:
    insrow = insrows.newRow()
    insrow.ID = id
    insrows.insertRow(insrow)

del row
del rows
del insrow
del insrows

PS - this is largely a community forum (ie. users answer questions on their own time), so don't be bitter if your question goes unanswered. Especially if it's not in the correct forum - this should be in 'Geoprocessing'.
JamesDuBois
New Contributor II

Thanks for the assistance.. It turns out that I don't need to have a draw order field that starts at 0 every time for Tableau, it just needs to be sequential. So if I add a new field that mimics the FID field, it should do the trick.