I created a map series layout in ArcGIS Pro, and try to update it from a Python toolbox, using Cartographic Information Model (CIM).
Each time the toolbox is running, the layer used to display tableFrame in the layout is overwritten. As the link with the tableFrame is lost during the process, I loop in layout elements to find my tableFrame, get the URI (unique id) of the layer of interest and use it to set the tableFrame's mapMemberURI.
aprx = arcpy.mp.ArcGISProject("CURRENT")
lyt = aprx.listLayouts('AinsiC_Paysage_Atlas_statsDynamiques_lots_v2')[0]
ms = lyt.mapSeries
mf = lyt.listElements('MAPFRAME_ELEMENT', 'Map Frame Series')[0]
mapSeriesLyr = mf.map.listLayers('Reserve_castor')[0]
m = aprx.listMaps("Map2")[0]
lyt_cim = lyt.getDefinition("V2") # Get the layout's CIM definition
for elm in lyt_cim.elements:
if elm.name == "Type_subsistance":
subsi = m.listLayers('Clip_Subsi_Dissolve1')[0]
subsi_cim = subsi.getDefinition('V2')
subsi_URI = subsi_cim.uRI
elm.mapMemberURI = subsi_URI
lyt.setDefinition(lyt_cim)
# Force a refresh of the layout and its associated panes
lyt_cim = lyt.getDefinition('V2')
lyt.setDefinition(lyt_cim)
This last step shows no error, but the tableFrame doesn't appear and I can see in the element pane that no layer is selected in the Table parameter.
I noticed that when I select the table in the interface, and extract the URI from Python script, the URI is *'CIMPATH=map2/clip_subsi_dissolve1.json'*, but when I use the name of the layer to extract the URI, it is *'CIMPATH=map2/clip_subsi_dissolve12.json'*.
What am I missing?