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<SPAN class="punctuation token">.</SPAN>SetParameter<SPAN class="punctuation token">(</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"SidewalkSections"</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># "SidewalkSections" refers to the layer in the current map that is being edited</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN></SPAN>
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:
<SPAN class="keyword token">import</SPAN> arcpy
sde_conn <SPAN class="operator token">=</SPAN> r<SPAN class="string token">'C:\Users\xyz\AppData\Roaming\ESRI\Desktop10.7\ArcCatalog\sde_MASTER.sde'</SPAN>
p <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>mp<SPAN class="punctuation token">.</SPAN>ArcGISProject<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"CURRENT"</SPAN><SPAN class="punctuation token">)</SPAN>
m <SPAN class="operator token">=</SPAN> p<SPAN class="punctuation token">.</SPAN>listMaps<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Streets"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN>
layers <SPAN class="operator token">=</SPAN> m<SPAN class="punctuation token">.</SPAN>listLayers<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
ap <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Describe<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Address Pts"</SPAN><SPAN class="punctuation token">)</SPAN>
sws <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Describe<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Sidewalks/SidewalkSections"</SPAN><SPAN class="punctuation token">)</SPAN>
inputAP <SPAN class="operator token">=</SPAN> ap<SPAN class="punctuation token">.</SPAN>FIDset
inputSWS <SPAN class="operator token">=</SPAN> sws<SPAN class="punctuation token">.</SPAN>FIDset
<SPAN class="keyword token">if</SPAN> <SPAN class="string token">";"</SPAN> <SPAN class="keyword token">in</SPAN> inputAP <SPAN class="operator token">or</SPAN> <SPAN class="string token">";"</SPAN> <SPAN class="keyword token">in</SPAN> inputSWS<SPAN class="punctuation token">:</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>AddMessage<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Error: select exactly 1 Address point and 1 Sidewalk section"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">elif</SPAN> len<SPAN class="punctuation token">(</SPAN>inputAP<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">==</SPAN> <SPAN class="number token">0</SPAN> <SPAN class="operator token">or</SPAN> len<SPAN class="punctuation token">(</SPAN>inputSWS<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">==</SPAN> <SPAN class="number token">0</SPAN><SPAN class="punctuation token">:</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>AddMessage<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Error: select exactly 1 Address point and 1 Sidewalk section"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">else</SPAN><SPAN class="punctuation token">:</SPAN>
query_ap <SPAN class="operator token">=</SPAN> <SPAN class="string token">"OBJECTID in ({0})"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>inputAP<SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>AddMessage<SPAN class="punctuation token">(</SPAN>query_ap<SPAN class="punctuation token">)</SPAN>
query_sws <SPAN class="operator token">=</SPAN> <SPAN class="string token">"OBJECTID in ({0})"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>inputSWS<SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>AddMessage<SPAN class="punctuation token">(</SPAN>query_sws<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">with</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>da<SPAN class="punctuation token">.</SPAN>SearchCursor<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Address Pts"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="string token">"FullAdd"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"ParcelID"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"RECORD_NUM"</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> query_ap<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> cursor<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">for</SPAN> row <SPAN class="keyword token">in</SPAN> cursor<SPAN class="punctuation token">:</SPAN>
ap_fullAdd <SPAN class="operator token">=</SPAN> row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN>
ap_ParcelID <SPAN class="operator token">=</SPAN> row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN>
ap_RecordNum <SPAN class="operator token">=</SPAN> row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">]</SPAN>
edit <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>da<SPAN class="punctuation token">.</SPAN>Editor<SPAN class="punctuation token">(</SPAN>sde_conn<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">try</SPAN><SPAN class="punctuation token">:</SPAN>
edit<SPAN class="punctuation token">.</SPAN>startEditing<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
edit<SPAN class="punctuation token">.</SPAN>startOperation<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">with</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>da<SPAN class="punctuation token">.</SPAN>UpdateCursor<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Sidewalks/SidewalkSections"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="string token">"Address_ap"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"parcelID_ap"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"RecNum_ap"</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> query_sws<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> cursor<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">for</SPAN> row <SPAN class="keyword token">in</SPAN> cursor<SPAN class="punctuation token">:</SPAN>
row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> ap_fullAdd
row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> ap_ParcelID
row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> ap_RecordNum
cursor<SPAN class="punctuation token">.</SPAN>updateRow<SPAN class="punctuation token">(</SPAN>row<SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>AddMessage<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"SidewalkSections"</SPAN><SPAN class="punctuation token">)</SPAN>
edit<SPAN class="punctuation token">.</SPAN>stopOperation<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
edit<SPAN class="punctuation token">.</SPAN>stopEditing<SPAN class="punctuation token">(</SPAN><SPAN class="token boolean">True</SPAN><SPAN class="punctuation token">)</SPAN>
fc <SPAN class="operator token">=</SPAN> <SPAN class="string token">"{0}\\STREETS\\SidewalkSections"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>sde_conn<SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>SetParameter<SPAN class="punctuation token">(</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"SidewalkSections"</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># "SidewalkSections" refers to the layer in the current map that is being edited</SPAN>
<SPAN class="keyword token">except</SPAN> Exception <SPAN class="keyword token">as</SPAN> err<SPAN class="punctuation token">:</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>AddMessage<SPAN class="punctuation token">(</SPAN>err<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">if</SPAN> edit<SPAN class="punctuation token">.</SPAN>isEditing<SPAN class="punctuation token">:</SPAN>
edit<SPAN class="punctuation token">.</SPAN>stopOperation<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>AddMessage<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"operation stopped in except"</SPAN><SPAN class="punctuation token">)</SPAN>
edit<SPAN class="punctuation token">.</SPAN>stopEditing<SPAN class="punctuation token">(</SPAN><SPAN class="token boolean">False</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="comment token">## Stop the edit session with False to abandon the changes</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>AddMessage<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"edit stopped in except"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">finally</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="comment token"># Cleanup</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>ClearWorkspaceCache_management<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>