Recently I've ramped up my exposure to Python coding and I'm currently working on a workflow which utilizes a layer class to export images retrieved from extents derived from selected features. The workflow currently loops through each of the selected features within the layer class and then exports that view/extent as a .JPEG. This is all great! But I'm trying to configure a dynamic naming convention which will utilize the values within the attribute table to name files and having some trouble.
The simple naming convention for the "exportToJPEG" step currently just adds a value of x to the end of the file name prefix. Instead I would like this step to grab text values from a "Bounding_Area" column within the "Bounding Box" attribute table so that the file name convention looks something more like:
lyt.exportToJPEG(r"P:\testOutBound" + "_" + "Bounding_Area")
lyt.exportToJPEG(r"P:\testOutBound" + str(x))
My current code looks like this:
import arcpy aprx = arcpy.mp.ArcGISProject(r"P:\test.aprx") arcpy.env.workspace = "P:\testing.gdb" arcpy.env.overwriteOutput = True arcpy.MakeFeatureLayer_management("P:\TestShapes.shp","BoundingBoxes") map = aprx.listMaps() layer = map.listLayers("BoundingBoxes") for x in range (1,20): obj = "ID=%s" % (x) arcpy.SelectLayerByAttribute_management(layer, "NEW_SELECTION", obj) lyt = aprx.listLayouts() mf = lyt.listElements('MAPFRAME_ELEMENT','*') mf.camera.setExtent(mf.getLayerExtent(layer,True,True)) mf.zoomToAllLayers() arcpy.SelectLayerByAttribute_management(layer,"CLEAR_SELECTION") lyt.exportToJPEG(r"P:\testOutBound" + str(x))
For similar dynamic path naming/path referencing Python tasks on other (non-arcpy) projects I've used the glob module or data frame column references but I'm not quite sure if either of those courses take the right approach.