You can do it via code.
import arcpy #Reference the Project document from within PRO aprx = arcpy.mp.ArcGISProject("CURRENT") #Reference the layout lyt = aprx.listLayouts("your_layout_name_here")[0] #Get the Map Frame mf = lyt.listElements("mapframe_element", "your_mapframe_name")[0] extent = mf.camera.getExtent() polygon = extent.polygon
You then have a polygon object that you can work with.
Note that this code just grabs the extent, if the map frame is rotated, the extent doesn't match what you see on screen.
Using tools in ArcToolbox
Create Fishnet (Data Management)—ArcGIS Pro | Documentation
Thank you sir! This worked marvelously.
Dan this works great as well! Thank you.
This worked great! Thank you!
Hi Mark,Can you please indicate how to save the extent as a feature class? I tried InsertCursor but it didn't accept the polygon object, it requires list of floats instead.Many thanks,
Katerina.
I realise there is a solution here but wanted to add a script for use in an ArcGIS Pro which creates a new polygon row in a feature class based on the current extent. The script also adds a scale from current extent to a field called SCALE (it will need to exist in feature class for it to work).This is particularly useful for users who are trying to build map books using data driven pages.Users will just need to create a script within a toolbox and add a parameter that is a feature layer type so that users can input a feature class for it to work. Here is script:
# Import system moduleimport arcpy
# Input parameter for feature class namefeature_class_name = arcpy.GetParameterAsText(0)
# Extracting the geodatabase path from the feature class namegeodatabase = "\\".join(feature_class_name.split("\\")[:-1])
# Ensure overwriting of output dataarcpy.env.overwriteOutput = True
# Select the current project mapaprx = arcpy.mp.ArcGISProject("CURRENT")
# Select the current map layoutmap_layout = aprx.listLayouts()[0]
# Extract the extent of the selected data framemap_frame = map_layout.listElements("MAPFRAME_ELEMENT")[0]extent = map_frame.camera.getExtent()polygon = extent.polygon
# Append a new row to the existing feature classarcpy.management.Append([polygon], feature_class_name, "NO_TEST")arcpy.AddMessage("Polygon appended to the existing feature class.")
# Get the current layout scalecurrent_scale = map_frame.camera.scale
# Check if the SCALE field existsfield_exists = Falsefor field in arcpy.ListFields(feature_class_name):if field.name == "SCALE":field_exists = Truebreak
if not field_exists:arcpy.AddError("SCALE field does not exist in the feature class.")else:# Update SCALE field for the newly added rowwith arcpy.da.UpdateCursor(feature_class_name, "SCALE") as cursor:for row in cursor:row[0] = current_scalecursor.updateRow(row)
arcpy.AddMessage("SCALE field updated for the newly added record.")Hopefully this saves someone some time 🙂
Přihlášení členové mohou přispívat, sledovat aktualizace a další. Jste tu noví? Zaregistrujte si bezplatný účet.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.