I am trying to update several fields in a mosaic dataset, to do this I am creating a mosaic layer and then running a loop over each row and calculating fields.

A NAME field contains a string which I would like to use to calculate several other fields. It is formatted like the following:


I would like to use split and use the output list indices in a field calculation (ie Project, Year and Date). The issue is I don't know to access the NAME field within a mosaic layer.

# create mosaic layer
mdl = arcpy.MakeMosaicLayer_management(md_path, "md_layer")

# calculate fields loop
print("Calculating fields in footprint...")
for lyr in mdl:
    split_name = lyr.NAME.split('_')
    arcpy.CalculateField_management(lyr, "YEAR", ????, "PYTHON")
    print("Year calculated...")
    arcpy.CalculateField_management(lyr, "PROJECT",????, "PYTHON")
    print("Project calculated...")

It falls over at the first step - split_name = lyr.NAME.split('_')-

AttributeError: 'Layer' object has no attribute 'NAME'

I would like to know the best approach to accessing specific fields within the mosaic layer.

  • 1
    NAME is not a property of an arcpy.Layer object. You likely want to access a field (in a DA SearchCursor) on the dataSource of the layer.
    – Vince
    Jan 6 at 3:18
  • See the 1st example (which uses split) in the help
    – user2856
    Jan 6 at 3:30
  • Thanking @Vince, I've started over with an UpdateCursor after being prompted by your reply and am having success. Cheers!
    – mapface
    Jan 6 at 5:15

Based on the 1st example (which uses split) in the help:

for lyr in mdl:  #Note replace PYTHON with PYTHON3 for ArcGIS Pro

    split_name = '!NAME!.split("_"){}'

    arcpy.CalculateField_management(lyr, "YEAR", split_name.format('[1]'), "PYTHON")
    print("Year calculated...")

    arcpy.CalculateField_management(lyr, "PROJECT", split_name.format('[0]'), "PYTHON")
    print("Project calculated...")

    arcpy.CalculateField_management(lyr, "DATE", split_name.format('[5]'), "PYTHON")
    print("Date calculated...")

However... an arcpy.da.UpdateCursor will probably be quicker than 3x arcpy.CalculateField_management calls as you can calculate all fields required at once.

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.