I created a Python Toolbox which calculates statisitics about some layers and print a pdf layout.
The layout and table frame elements already exist.
I try to access the table frame elements from my Python script to do some modifcations on fields to show, field order and table frame position.
aprx = arcpy.mp.ArcGISProject("CURRENT") # my project
m = aprx.listMaps("Map2")[0] # my map
lyr = m.listLayers("Clip_Reco_Dissolve1")[0] # source layer for the table frame
lyt = aprx.listLayouts('Tabloid_Paysage_Unique_test')[0] # my layout
fieldNames = ["Categorie", "COUNT_Categorie"] # fields to display
elm = lyt.listElements("GRAPHIC_ELEMENT", "Categorie ressource") # name of the table frame in the layout content
The only way I found in Esri documentation is using last row, but it is not working. I tried again after converting this element to graphic, but it doesn't work either, and anyway I need to manipulate it as table frame to manage fields, before changing its position.
elm = lyt.listElements("GRAPHIC_ELEMENT", "Categorie ressource")
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\utils.py", line 191, in fn_
return fn(*args, **kw)
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\_mp.py", line 1840, in listElements
return convertArcObjectToPythonObject(self._arc_object.listElements(*gp_fixargs((element_type, wildcard), True)))
RuntimeError
