how to extent of the map view in arcgis pro to the same size as polygon's feature class

1446
3
02-01-2021 02:03 AM
cinnaaaoo
New Contributor II

How to extent of the map view as an image format in arcgis pro to the same size as polygon's feature class?

From converting this code

import arcpy, os
aprx = arcpy.mp.ArcGISProject("CURRENT")
mv = aprx.activeView

# Change the extent of the map view
ext = mv.camera.getExtent()
ext.XMin = ext.XMin
ext.YMin = ext.YMin
ext.XMax = ext.XMax
ext.YMax = ext.YMax
mv.camera.setExtent(ext)
Output_File = os.path.join(arcpy.env.scratchFolder, 'ActiveMapView3.png')
mv.exportToPNG(Output_File, width=1000, height=1000)

 

0 Kudos
3 Replies
by Anonymous User
Not applicable

I think you can just use the MapFrame class to do this.

 

import arcpy
aprx = arcpy.mp.ArcGISProject(r"C:\Projects\YosemiteNP\Yosemite.aprx")

m = aprx.listMaps("Yose*")[0]
lyr = m.listLayers("Ranger Stations")[0]
lyt = aprx.listLayouts("Main Attr*")[0]
mf = lyt.listElements("mapframe_element", "Yosemite National Park")[0]
mf.camera.setExtent(mf.getLayerExtent(lyr, False, True))

aprx.exportToPNG(out_png, {resolution}, {world_file}, {color_mode}, {embed_color_profile})
del aprx

 

0 Kudos
cinnaaaoo
New Contributor II

I don't understand the coding of these 3 lines.

lyr = m.listLayers("Ranger Stations")[0]
lyt = aprx.listLayouts("Main Attr*")[0]
mf = lyt.listElements("mapframe_element", "Yosemite National Park")[0]

0 Kudos
by Anonymous User
Not applicable

Those are from the example in the Docs.

lyr = m.listLayers("Ranger Stations")[0]  < replace with the name of the layer in your project that you want to get the extent from


lyt = aprx.listLayouts("Main Attr*")[0]  < replace with your layout name in your project


mf = lyt.listElements("mapframe_element", "Yosemite National Park")[0]  < replace 'Yosemite National Park' with your element name from your layout

Take a read of the Discussion in the docs.  It explains the Layout and ListElements methods.  MapFrame 

0 Kudos