The following script joins two layers on a common id and attempts to use the OBJECTID in the joined table to update records for a field in the input table. In running it in "current" mode, it moves through the join process ok but then errors out with Calculate. OBJECTID is from a joined table and I am joining it to an Annotation class, but I'm not sure that is relevant. Any ideas as to why this doesn't complete?

    mxd = arcpy.mapping.MapDocument("Current")
    dflist = arcpy.mapping.ListDataFrames(mxd)
    for df in dflist:
        if df.name == "County":
            for lyr in (arcpy.mapping.ListLayers(mxd, "", df)):
                if lyr.name == "County Insets":
                    CoInset = lyr
                elif lyr.name == "County Insets Anno":
                    CoAnno = lyr
            print 'Joining ' + CoInset.name + ' to ' + CoAnno.name
            arcpy.AddJoin_management(CoAnno, "TempID", CoInset, "TempID")
            expression = "!" + CoInset.name +".OBJECTID!"
            arcpy.CalculateField_management(CoAnno, "FeatureID",  expression, "PYTHON")

This gives me the following error:

Runtime error  Traceback (most recent call last):   
File "<string>", line 14, in <module>   File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\management.py", line 3129, in CalculateField     raise e <br>
ExecuteError: ERROR 000539: Invalid field County Insets.OBJECTID Failed to execute (CalculateField).


expression = "!" + CoInset.datasetName +".OBJECTID!"

instead of:

expression = "!" + CoInset.name +".OBJECTID!"

The joined fieldnames should reflect the feature class/annotation's workspace name, not table-of-contents name.

| improve this answer | |
  • That was the trick! Thanks for the quick and on target response. It can be maddening trying to figure out simple syntax issues like this. Thanks for the help! – Bernie Sep 18 '14 at 18:17

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.