ArcPro Python tool - update table to show edited attributes

530
2
11-21-2019 12:46 PM
South_JordanCity_of
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!

Marc

this is the code:

import arcpy

sde_conn = r'C:\Users\xxx\AppData\Roaming\ESRI\Desktop10.7\ArcCatalog\sde_MASTER.sde'
p = arcpy.mp.ArcGISProject("CURRENT")
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")
else:
    query_ap = "OBJECTID in ({0})".format(inputAP)
    arcpy.AddMessage(query_ap)
    query_sws = "OBJECTID in ({0})".format(inputSWS)
    arcpy.AddMessage(query_sws)
    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)
    try:
        edit.startEditing()
        edit.startOperation()

        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
                cursor.updateRow(row)
        arcpy.AddMessage("SidewalkSections")

        edit.stopOperation()
        edit.stopEditing(True)
        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:
        arcpy.AddMessage(err)
        if edit.isEditing:
            edit.stopOperation()
            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")
    finally:
        # Cleanup
        arcpy.ClearWorkspaceCache_management()

‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos
2 Replies
JoeBorgione
MVP Emeritus

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
South_JordanCity_of
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