Hello,
I have created 100 layouts that I need to refine their legend one by one using python CIM access. I'm looping through them and my code looks like below:
import arcpy
aprx = arcpy.mp.ArcGISProject("CURRENT")
# I stored the 100 features (the "featureclasses") I want to loop through in a gdb called "spp_gdb"
# and I already exported them into layouts using their feature class names respectively (they are in the form of "D:/Pro_Projects/layouts/Layout_"+ fc + ".pagx")
arcpy.env.workspace = r"D:/Pro_Projects/Project_may10th2021/spp_gdb.gdb"
featureclasses = arcpy.ListFeatureClasses()
# create a for loop
for fc in featureclasses:
aprx.importDocument(r"D:/Pro_Projects/layouts/Layout_"+ fc + ".pagx")
# get the newly imported layout
x = aprx.listLayouts()[-1]
# and check its name
print(x.name)
x_cim = x.getDefinition('V2')
# here, I did something with python CIM and then I saved my edits
x.setDefinition(x_cim)
# map layout export
x.exportToPNG(r"D:/Pro_Projects/Map_"+ fc + ".png", resolution = 300)
print("loop finished")
However, there seems to be a layout jam in the end since I did not delete each layout I added to the current project every time. The print (x.name) that I used to check the added layout name started to return the same value when it reached layout9. (does it mean 9 layouts maximum in a single Pro project?)
This problematic access of layout names affected this automated refinement and I was getting identical map exports in my output folder. I wonder if there is a way to delete added layouts using arcpy scripts in Pro to keep my intended loop functioning?
Regards,
Ming
if "x" is the layout and you want to delete it did you try
del x
in your script?
I just tried it, but it has no effect on stopping the layout name to go up, once I got "layout9" it starts to make replicates for me just like before. it looks like the previous layouts get stored inside the current project..
Could you do this task another way?
If the end result needed is just a set of pngs, why not use data driven pages based off the features in your gdb?
Thank you for your reply! But the png set I hope to create is not of different map extents from 1 single layout, rather it's 1 basemap overlaid by one specific species layer each time, I don't think data driven pages can achieve this purpose.
I know it has been a long time since the post was written but, did you solve the problem? I have the same issue with an imported layout in a loop
Thanks
@VíctorAEhi!
Hi! My ArcPy does not have implemented that functionality. I tried to use a layout template as you did, but I have a table created from scratch and, I don´t know why, but the reference is lost in the iteration
Thanks a lot!