1

Update: Problem Solved

I fixed it. In the Calculate Field Tool within Model Builder, I entered "!shape.area@acres!" . That resolved the issue and the model now produces the same results as the python script

#

I would like to use the Calculate Field tool in ModelBuilder of ArcMap 10.5 to calculate the acres of a polygon. I understand that in python I can write !shape.area@acres!, but I'm unsure how to set up the script for the Calculate Field tool.

Update:

I can successfully run my python script within the python window, however I cannot run a model builder tool that should perform the same function. the error is as follows: ERROR 000539: SyntaxError: invalid syntax (, line 1) Failed to execute (Calculate Field).

My python script is here:

# Import arcpy module
import arcpy

#set path
arcpy.env.workspace = "C:/desktop/TestScripting.gdb"

# Script arguments
Add_Parameter = arcpy.GetParameterAsText(0)
if Add_Parameter == '#' or not Add_Parameter:
    Add_Parameter = "LonokeCounty2" # provide a default value if unspecified

LonokeCounty2__2_ = arcpy.GetParameterAsText(1)
if LonokeCounty2__2_ == '#' or not LonokeCounty2__2_:
    LonokeCounty2__2_ = "LonokeCounty2" # provide a default value if unspecified

# Local variables:
LonokeCounty2 = LonokeCounty2__2_
LonokeCounty2_Statistics = "C:\\Users\\chris\\Documents\\ArcGIS\\Default.gdb\\LonokeCounty2_Statistics"

# Process: Add Field
arcpy.AddField_management(Add_Parameter, "Acres2", "FLOAT", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")

# Process: Calculate Field
arcpy.CalculateField_management(LonokeCounty2__2_, "Acres2", "!shape.area@acres!", "PYTHON", "")

closed as off-topic by PolyGeo Sep 18 '17 at 2:28

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This problem cannot or can no longer be reproduced. Changes to the system or to the asker's circumstances may have rendered the question obsolete, or the question does not include a procedure to enable potential answerers to reproduce the same symptoms. Such questions are off-topic as they are unlikely to help future readers, but editing them to include more details can lead to re-opening." – PolyGeo
If this question can be reworded to fit the rules in the help center, please edit the question.

  • I think this should be straightforward. What have you tried? – PolyGeo Sep 17 '17 at 19:25
  • What is in your model and what is the precise error message? Please use the edit button beneath your question to revise it with any requested clarifications. – PolyGeo Sep 17 '17 at 21:10
  • Do you always want to calculate in the same field you're adding? I'm not sure why there's two parameters. – Marc Pfister Sep 17 '17 at 21:39
  • 2
    I believe it is !Shape!.area – FelixIP Sep 17 '17 at 22:06