1

In Modelbuilder I have set up a model, where in one step I do a "Calculate Field" like "round((!OID!-1- %MyField% /15)/452,1)+1" . For the calculation i use the value of %MyField%, which actually is an Value of a specific Field in the first Row of a Table. I tried to retrieve is with "Get Field Value" - this works. But how do I ensure, that I have the value retrievet at the moment when I want to "Calculate Field"? Of cource I make an "Precondition" connection, but if "MyField" is 0 (Zero), the precondition says False, so the Calculate Field is not executed. To explain more: I iterate through features (A) in feature class. In the iteration model i create an fishnet (new feature class (B)) inside the feature. Then i add a field to the new feature class (B).Now i need to calculate this field using the formula mentioned above. In the formula i need to use a value from a field of the feature (A). Is there a way? (I use Arcgis 10.2)

2
  • Field calculations can only work on a single row in a table - they do not have access to data in other rows. In order to use a field calculation your constant must be present in every row, or hard-coded into the formula.
    – Chris W
    Nov 18, 2014 at 20:00
  • Would you be able to edit your question to include a picture of the relevant part of your model, please? Also, include the version of ArcGIS for Desktop that you are using because ModelBuilder has had quite a few changes between 9.3 and now.
    – PolyGeo
    Nov 21, 2014 at 7:00

1 Answer 1

1

Finally I solved this problem. I have to use a short python-script:

import arcpy
myFeature = arcpy.GetParameterAsText(0)
myrows = arcpy.SearchCursor(myFeature)
myrow = myrows.next()
MyField = myrow.getValue("Offset_Y")
arcpy.SetParameter(1, MyField)
arcpy.SetParameter(2, True)

Where Parameter 0 as Input is the feature where the field "Offset_Y" is. Parameter 1 as Output is the value I want in the Variable, Parameter 2 as Output is Boolean and connected to Calculate Field Value.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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