Select to view content in your preferred language

Model Builder calculate field expression

1306
11
03-16-2022 11:08 AM
2Quiker
Occasional Contributor II

I have a model that I would like to use the the following code to update a field "Permits" based on how many text occurrences are in "ParcelNum1" field based on the "PermitNum" field. I get the following error and need help figuring out what the issues is and all fields are text fields. I need this in model builder.

Example

OBJECTIDPermitNumParcelNum1Permits
1aa11231234512345, 12346
2aa112312346 
3BB33616789167891, 67892, 37893
4BB336167892 
5BB336167893 
6UU98321112311123
7PP222569896988, 6989
8PP22256988 

Pre-Logic Script code:

 

 

 

 

 

 

dict1 = dict()
with arcpy.da.SearchCursor('TableTest6',['ParcelNum1','Permit_Count','PermitNum']) as cursor:
    for row in cursor:
        if row[0] not in (None, "", " "):
            dict1.setdefault(row[0],[]).append(str(row[2]))
        
def concat(nf):
    x = None
    if nf in dict1t:
        x = ",".join(dict1[nf])
    return x

 

 

 

 

 

 

Permits = conact(!ParcelNum1! )

 

Error.

ERROR 000539: Runtime error
Traceback (most recent call last):
File "<string>", line 2, in <module>
RuntimeError: cannot open 'TableTest6'

Failed to execute (Calculate Field (4)).

0 Kudos
11 Replies
RhettZufelt
MVP Notable Contributor

Funny, I thought I posted the below post earlier, but was still sitting as draft....

 

Still having issues with TableTest6.  

have you tried hard coding the path to that table?

 

with arcpy.da.SearchCursor(r'C:\path2table\TableTest6',['ParcelNum1','Permit_Count','PermitNum']) as cursor:

 

 

You can open the python window from Catalog and enter each command one at a time.

Can print individual variable results, etc.  This can often give you more info on where it is failing.

R_

0 Kudos
RhettZufelt
MVP Notable Contributor

Documentation for model builder says that items in the drop-down (TableTest6) is a variable.

You could try putting it in the cursor as a variable instead of text:

with arcpy.da.SearchCursor(TableTest6,['ParcelNum1','Permit_Count','PermitNum']) as cursor:

 

and see if that works.

Otherwise, just hardcode the path and you are don.

R_

 

 

0 Kudos