ArcPro Python tool - update table to show edited attributes

11-21-2019 12:46 PM
Occasional Contributor

Hi all,

I'm sure this has been asked before, but I was not able to find an answer to my problem:

I created a python tool within a toolbox in ArcPro. The tool grabs 3 attributes from a selected address point (record number, address, parcelID) with a SearchCursor and updates 3 attributes from a different selected feature (sidewalk section) with these values through an UpdateCursor. The tool runs without errors and does what it is supposed to do.

However, the changes won't show up in ArcPro unless I either refresh the database (SDE), which is greyed out for the most part, or unless I create any other feature and hit the save button. I then have to clear the selection and re-select the sidewalk segment for the changes made by the tool to appear.

I read on different posts that the layer edited by the tool has to be set in the tool parameters as an derived output in order to tell the system that datasets were modified by the script.

So I tried that with these output parameters in the tool and this line in my script:


arcpy.SetParameter(0, "SidewalkSections")   # "SidewalkSections" refers to the layer in the current map that is being edited

The tool runs fine, but the output behavior doesn't change. What am I missing here?

Thanks for your help!


this is the code:

import arcpy

sde_conn = r'C:\Users\xxx\AppData\Roaming\ESRI\Desktop10.7\ArcCatalog\sde_MASTER.sde'
m = p.listMaps("Streets")[0]
layers = m.listLayers()

ap = arcpy.Describe("Address Pts")
sws = arcpy.Describe("Sidewalks/SidewalkSections")
inputAP = ap.FIDset
inputSWS = sws.FIDset
if ";" in inputAP or ";" in inputSWS:
    arcpy.AddMessage("Error: select exactly 1 Address point and 1 Sidewalk section")
elif len(inputAP) == 0 or len(inputSWS) == 0:
    arcpy.AddMessage("Error: select exactly 1 Address point and 1 Sidewalk section")
    query_ap = "OBJECTID in ({0})".format(inputAP)
    query_sws = "OBJECTID in ({0})".format(inputSWS)
    with arcpy.da.SearchCursor("Address Pts", ["FullAdd", "ParcelID", "RECORD_NUM"], query_ap) as cursor:
        for row in cursor:
            ap_fullAdd = row[0]
            ap_ParcelID = row[1]
            ap_RecordNum = row[2]

    edit = arcpy.da.Editor(sde_conn)

        with arcpy.da.UpdateCursor("Sidewalks/SidewalkSections", ["Address_ap", "parcelID_ap", "RecNum_ap"], query_sws) as cursor:
            for row in cursor:
                row[0] = ap_fullAdd
                row[1] = ap_ParcelID
                row[2] = ap_RecordNum

        fc = "{0}\\STREETS\\SidewalkSections".format(sde_conn)
        arcpy.SetParameter(0, "SidewalkSections")   # "SidewalkSections" refers to the layer in the current map that is being edited

    except Exception as err:
        if edit.isEditing:
            arcpy.AddMessage("operation stopped in except")
            edit.stopEditing(False)  ## Stop the edit session with False to abandon the changes
            arcpy.AddMessage("edit stopped in except")
        # Cleanup

0 Kudos
2 Replies
MVP Esteemed Contributor

Marc- just a suggestion, use the syntax highlighter for your code.  Makes reading and referring to lines much easier.  I'm going to send a ping to colleague Joshua Bixby and see if he has a trick or two for you.

That should just about do it....
0 Kudos
Occasional Contributor

Thanks Joe. post is updated.

I was actually looking for the code highlighting function, but I couldn't find it. I missed the Expand Toolbar button....

0 Kudos