Model Builder - Select, Select by Attribute, Calculate Field, and Coded Domains

06-10-2014 04:21 AM
New Contributor
Two issues:

1) I'm trying to build a model that will take the table of a feature class and replace certain values in the same feature class. Example:

I have [field] with values (coded domains) of -1, 1, 2, 3, 4, X. Every time the coded domain is -1, I want to replace it with X.

There are ~15 fields that I want to do this with. Currently I am using Select Layer By Attribute, however this seems to mean that I have to have the layer in the .mxd to use the tool, and I would ideally like to run it from catalog. If I switch to using Select then I get a new feature class of my selection which will not work because in the end I need the whole table (or maybe there is a way it will work that I'm just not aware of yet).

Is there another tool to use, or a code block that I can tweak (there has to be...) in the Calculate field tool to select the records I want to change? I'm pretty decent with programming logic, but syntax is another issue entirely.

2) I have a coded domain value of 001, stored as text. I want to create a variable paramater for the model where the input will be exactly 001 and this will be used to calculate the field value. The problem is that every way that I do this the field updates to 1... unless I enclose 001 in double quotes. I was hoping to use the variable for other calculations where the quotes are not neccessary, and it would be best if I didn't need to rely on the user to read instructions about putting this parameter in double quotes (plenty of headaches could be avoided). Any way to do this??
0 Kudos
1 Reply
Regular Contributor II
You could use CalculateField_management  for the first problem
using a code block that tests the existing value
and if it is -1, change it to X
and otherwise leave it alone.

With 15 fields to test, an update cursor with a similar test may be advisable.

for the second problem, you can accept the input as a string
as (for example: 1, 01 or 001) and use zfill(3) to pad out the entered string with zeros.

Now, whenever you want to use it as a number just convert it to an integer
int("001") returns 1

Integers don't have leading zeros, so they get stripped off
and however the user entered the string (for example, again: 1, 01 or 001)
the string gets padded to "001"
0 Kudos