Zooming in Using ArcPy

1787
7
Jump to solution
07-07-2022 07:46 AM
MM598
by
Occasional Contributor

I am working in ArcPro and trying to create a print tool in which the user makes a point, then the camera zooms into the polygon within that point, and a report is generated with the layout zoomed into that polygon. Any suggestions for code I could use to zoom into a selected polygon?

Edit: removed extraneous information, clarity

0 Kudos
1 Solution

Accepted Solutions
DannyMcVey
Esri Alum

This method is working fine for me in the Pro python window.

 

aprx = arcpy.mp.ArcGISProject("CURRENT")
mv = aprx.activeView # mapview
m = mv.map # map
mv.camera.setExtent(mv.getLayerExtent(m.listLayers('USA_Counties_Generalized')[0]))

This works because "getLayerExtent" honors any active selection.

 

View solution in original post

0 Kudos
7 Replies
RhettZufelt
MVP Notable Contributor

You must be in Pro?  Since arcpy.mapping (ArcMap) was replaced with arcpy.mp.  Should be able to find what you need there.

R_

 

0 Kudos
MM598
by
Occasional Contributor

Unfortunately, arcpy.mapping does not translate easily to arcpy.mp.

0 Kudos
DanPatterson
MVP Esteemed Contributor

Solved: Zoom/Pan to layer using Arcpy - Esri Community

a suggestion from one of the links to the right of your thread


... sort of retired...
0 Kudos
MM598
by
Occasional Contributor

No, arcpy.mapping is deprecated and does not translate easily to arcpy.mp.

0 Kudos
RhettZufelt
MVP Notable Contributor

Not sure what you mean by "deprecated".  If you are using ArcMap, then you use arcpy.mapping.  If you are on Pro, it's arcpy.mp.

The link I provided makes it easier to "translate" to arcpy.mp.   

Maybe someone else knows a different way, but I think these are your options to control the "Map" with arcpy.

 

R_

 

DannyMcVey
Esri Alum

This method is working fine for me in the Pro python window.

 

aprx = arcpy.mp.ArcGISProject("CURRENT")
mv = aprx.activeView # mapview
m = mv.map # map
mv.camera.setExtent(mv.getLayerExtent(m.listLayers('USA_Counties_Generalized')[0]))

This works because "getLayerExtent" honors any active selection.

 

0 Kudos
MM598
by
Occasional Contributor

This works. However, it is not working in ArcOnline once I upload the tool. That may call for a different post. . . Thanks for your help!

 

0 Kudos