Is it possible to identify the selected - or active - map frame? If this is obvious, sorry, but I have not been able to find it. I have a script that creates a polygon from a map frame extent and the user has to enter the map name to make sure I am running on the right map frame (the script picks the map frame based on the map that is selected. Kind of awkward, but may be necessary).
Thank you,
Randy
Hi Josh
That is what I ran and I receive the following error:
RuntimeError Traceback (most recent call last)In [74]:Line 7: mf.camera.setExtent(mf.getLayerExtent(lyr))
File C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\_mp.py, in getLayerExtent:Line 2150: return convertArcObjectToPythonObject(self._arc_object.getLayerExtent(*gp_fixargs((layer, selection_only, symbolized_extent), True)))
RuntimeError:
I'd start with the Introduction to arcpy.mp article. There are some linked tutorials that can walk you through some of the simpler procedures.
Basically, you'd use something like this:
import arcpy aprx = arcpy.mp.ArcGISProject('CURRENT') # get your layout lyt = aprx.listLayouts('Your Layout Name')[0] # get the map frame mf = lyt.listElements('MAPFRAME_ELEMENT', 'your map frame name')[0] # note that the name of the frame is NOT the name of the map # get specific layer you want lyr = mf.map.listLayers('Your Layer Name')[0] # set frame extent to match layer mf.camera.setExtent(mf.getLayerExtent(lyr))
Thanks for pointer around etiquette.
I have an empty map frame in a layout that I want to set the map view in and then zoom to the extent of one of the layers. I can't seem to get off the ground with this one or find much help on the web. Any assistance would be appreciated. Seems like it a fairly simple standard thing to want to do?
Matt
Even if it's the same text, it's a good practice to put your question in both the title and body of your posts here.
What you're looking for is Camera.setExtent(), which you can read up on here: https://pro.arcgis.com/en/pro-app/latest/arcpy/mapping/camera-class.htm
Les membres connectés peuvent publier, suivre les mises à jour, et plus encore. Nouveau ici ? Inscrivez-vous gratuitement.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.