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)
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.