I have a model which iterates through a GDB, populating the same attribute field in every feature class with a parameter value. In this way I can mark all FC's in the geodatabase as to what project they are a part of.

However, sometimes a GDB contains FC's which are migrated from other GDB projects, with the attribute already populated with a value designating it as part of the other project. Currently my model stomps on this value and overwrites it with the new project code, whereas I want to retain the existing information.

I would like to have the model evaluate the field for the record it is working with, and if the field is not empty, to leave the field alone and move to the next record. However if the field is then it should write the new project code to the field and move on.

I've looked into a bit of the if/then questions and answers but have not found a simple way to detect if a field is empty or not, and if not, how to skip it?

I am now trying to write some Python to handle it and have the following, however I am not sure how to get the parameter value from the user entry in the model (ie. UserInputFromModelParameter), or what command to send to make the script skip to the next record if the script is true.

# set up variables
def BlockName:

def IgnoreField:

# set block name from user inpuit
BlockName = [UserInputFromModelParameter]

# set values to watch for
IgnoreField = [NULL, ""]

# evaluate the field

    if [BlockID] == IgnoreField

        [BlockID] = BlockName();
  • 1
    How is the model updating the attributes? Without knowing the specific tools/steps it's kind of hard to offer suggestions. A simple check on a field value of whether it IS NULL or is ="" would tell you if the field was 'empty' (depending of course on your definition of empty). – Chris W Mar 31 '15 at 1:43
  • The model updates via a Calculate Field process. It has three sub models and one parent model, the three sub models each have an iterator which runs through all the feature classes of a certain type (line, point, poly) changing a specific field ("BlockID") in all feature classes of that type to a string parameter set by the user. How would I insert the check on the field value to see if it is NULL or ""? (sorry, my scripting skills are weak) – user25644 Apr 1 '15 at 18:57
  • That should be fairly easy. Within the CF tool there should be a code block you can use for a pre-logic script. You'd put an if statement in there to check for null. We have a lot of questions on if statements in the field calculator, for example gis.stackexchange.com/questions/111432 (Python) and gis.stackexchange.com/questions/136816 (VBScript). So you'd put something like if field is null or field = "" then result = newprojectcode else result = field in the code block and then result in the actual calculation box (following the VB example). – Chris W Apr 1 '15 at 20:23
  • Seems simple enough, however the user defines what value to put into empty fields when running the script, so i need to have that as part of the if/then. So, using VB I have: if [BlockID] <> "" then result = [UserInputHere] else result = [BlockID] end if .....So how do I assign the parameter from the model to the UserInputHere? Thanks. – user25644 May 25 '15 at 20:56
  • You should be able to expose that as a parameter to the CF tool. See gis.stackexchange.com/questions/109673 for code example. I think you just right-click the tool and choose make parameter or something in ModelBuilder (just going from memory here, haven't tested or checked this). – Chris W May 25 '15 at 21:07

I wrote some VB code to try and handle this with an if/then, seemed a bit more simple than python.

Here is the code, %BlockID (in quotes)% is the user input value, [BlockID] is the field being evaluated/written, and Expression = "Output".

If IsNull([BlockID]) Then

Output = %Block (in quotes)%

Elseif [BlockID] <= "" Then

Output = %Block (in quotes)%


Output = [BlockID]

End If

...seems to be working, though bails out with an error if it hits a FC without "BlockID" field.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.