0

In ArcMap you can calculate a field on a joined table to just move the attributes from one column to another with just an = sign. Since my layer has feature linked anno on 7 different layers the calculation has to be done in an edit session. I tried this and it ran over three hours and not sure if it was going to finish. This won't work since I have to do this on about 30 fields.

I am trying to do this in ArcPy. I was using arcpy.CalculateField_management. I don't think that works based on the error I received. The error is invalid property. I think this means that it wants to make a calculation not just move attributes.

Here is my sample code:

import arcpy
from arcpy import env

anno_conn = "\\\\any database"
env.workspace = anno_conn

#Variables
Table_A = "data_1"
Table_B = "data_r3"
Layer_A = Table_A + "_lyr"
Layer_B = Table_B + "_lyr"

try:
    #join tables
    arcpy.MakeFeatureLayer_management(Table_A, Layer_A)
    arcpy.MakeFeatureLayer_management(Table_B, Layer_B)

    arcpy.AddJoin_management(Layer_A, "visi_link", Layer_B, "prior_visi")

    # Using an edit session - feature linked layer can't be edited outside an edit session      
    # inside try edits will be saved if successful, will roll back if an exception is thrown
    with arcpy.da.Editor(env.workspace) as edit:
        arcpy.CalculateField_management(Layer_A, Table_A + ".link_id", "!" + Table_B + ".link_id!", "PYTHON")

except Exception, err:
    traceback.print_exc()

It seems to work up until the Calc field line.

2

There are a couple of ways to accomplish this. If I am understanding what you are attempting to do correctly, you want to populate fields in the second table with values from the first.

The tact you are attempting is very ArcGIS centric and will definitely work. However, the more programmatic way to attempt this, one designed to run much faster in Python, is to use the update cursor from the arcpy data access module.

Also, although you likely just changed it when pasting into this editor, remember to play very close attention to your indentation. Your block of code between try and except, if not indented, will throw an error.

Finally, I did try and refactor your code a bit, but was not sure what the source and target field names are. Looking at your code above, they look almost identical. It may just be a simple step of including the source layer name in front of the dot notation. However, without a sample dataset to test against, it is hard to ascertain.

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.