Trying to update data source for layers in ArcGIS Pro maps programmatically. So, I must be misunderstanding the syntax for doing that explained here. Because the following does not work:
<SPAN class="keyword token">import</SPAN> arcpy
aprx <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>mp<SPAN class="punctuation token">.</SPAN>ArcGISProject<SPAN class="punctuation token">(</SPAN>r<SPAN class="string token">'path to my project file'</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token">#This gets me list of all the maps</SPAN>
maplist <SPAN class="operator token">=</SPAN> aprx<SPAN class="punctuation token">.</SPAN>listMaps<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token">#If I only want those belonging to MyGroup</SPAN>
mygroup <SPAN class="operator token">=</SPAN> aprx<SPAN class="punctuation token">.</SPAN>listMaps<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'MyGroup'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="comment token">#To get the layers in that group</SPAN>
grouplayers <SPAN class="operator token">=</SPAN> mygroup<SPAN class="punctuation token">.</SPAN>listLayers<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
new_sdeConn <SPAN class="operator token">=</SPAN> r<SPAN class="string token">'path to my SDE connection file'</SPAN>
<SPAN class="keyword token">for</SPAN> lyr <SPAN class="keyword token">in</SPAN> grouplayers<SPAN class="punctuation token">:</SPAN>
old <SPAN class="operator token">=</SPAN> lyr<SPAN class="punctuation token">.</SPAN>connectionProperties <SPAN class="comment token">#also tried lyr.connectionProperties['connection_info']</SPAN>
lyr<SPAN class="punctuation token">.</SPAN>updateConnectionProperties<SPAN class="punctuation token">(</SPAN>old<SPAN class="punctuation token">,</SPAN> new_sdeConn<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>This doesn't throw an error. it just doesn't do update the data sources as desired. The ESRI example goes like:
aprx<SPAN class="punctuation token">.</SPAN>updateConnectionProperties<SPAN class="punctuation token">(</SPAN>r<SPAN class="string token">'C:\Projects\YosemiteNP\Vector_Data\Yosemite.gdb'</SPAN><SPAN class="punctuation token">,</SPAN>
r<SPAN class="string token">'C:\Projects\YosemiteNP\DBConnections\Server.sde'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN></SPAN>Does this maybe only work for the project as a whole?