I have to generate line dimension annotation for our maps as a part of my daily workflow. As it stands, I've been using

round(float(!Distance!), 2)

for straight lines, then switching the selection in the table to reselect the curve lines and running

round(float(!ArcLength!), 2)

in the Field Calculator geoprocessing tool to take the raw values and round them to two digits. I am trying to figure out a way to write an if/then statement so I only have to run the geoprocessing tool once.

This if/else statement doesn't return an error, but it doesn't calculate anything to the field. I haven't been able to find an example anywhere of what I'm trying to do. I'm assuming it's impossible, but there might be something I'm missing? I don't have any other options right now but to generate text annotation, using dynamic labeling will not work for our purposes. Currently using ArcMap 10.6.

def dimCalc(Distance,ArcLength):
   if (Distance == 0):
      return round(float(ArcLength),2)
      return round(float(Distance),2)
  • 2
    There is no "switch" in your code, how are you altering the selection between curved and straight lines?
    – Hornbydd
    Commented Nov 29, 2022 at 15:16
  • A curved line will have a 0 in the Distance field. Curves in my dataset are defined by ArcLength and Radius. Distance is reserved for straight lines.
    – annag
    Commented Nov 30, 2022 at 16:24
  • Your question says that you have a selection in the table. If that is the case, then clear (de-select) the selection. Field calculator will only work on selected records (if there is a selection). Commented Nov 30, 2022 at 23:11
  • 1
    What is the 'Expression' in your field calculator? If you replace the two return statements with return 1 and return 2, respectively, what happens then? If you replace the entire contents of your dimCalc() function with return 3, what happens then? Commented Nov 30, 2022 at 23:13

1 Answer 1


Are you sure distance is 0, maybe it's None/Null. Try this

def dimCalc(Distance,ArcLength):
   if (Distance == 0 or Distance is None):
      return round(float(ArcLength),2)
      return round(float(Distance),2)

Also make sure you are passing the fields correctly as you haven't shown this in your question

dimCalc ( !distance!, !arclength! )
  • you are correct, the Distance field is Null if there's no value. I reran the tool with that script, and it didn't fail but it didn't populate the field. Thanks! edit: I did pass the fields as you described in both the original attempt and with the updated script.
    – annag
    Commented Dec 1, 2022 at 16:37

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.