Zoom to layer on the map view arcpy.mp

11023
14
Jump to solution
04-12-2021 01:43 PM
MarvisKisakye1
Occasional Contributor

I am attempting to zoom to layer on the map view NOT the layout view. I am aware that I can zoom to a layer using the code below

cam = c_project.activeView.camera
ext = arcpy.Describe(layer).extent
cam.setExtent(ext)
c_project.save()
 
My issue is that c_project.activeView returns None because the project is not yet open. 
14 Replies
AndyAnderson
Occasional Contributor II

Ah, yes, Views have no names. But if that continues there could still be types, and the MapViews also provide links to their own Cameras, which do have extents, and links to their own Maps, which do have names, and these could be used to distinguish the different MapViews. But here are three additional ways one could tell them apart:

1) Assign the activeView to a variable before switching to a new one.

2) Ensure that the proposed listViews() method returns indexed Views in temporal order, and assign them to distinguishable variables; the latest would always be listViews()[-1].

3) When I tell a map to open a new MapView, assign that reference to a variable.

Just some thoughts!

— Andy

0 Kudos
JeffBarrette
Esri Regular Contributor

Andy, I'm not sure I understand your points or perhaps our 3.0 release will have your solution.  At 3.0 we can currently differential between these view types: Map, Layout and Other (where Other = table, report, model builder, etc).

But if you have a single "MapA" and have 3 views of it open, I'm not sure how you can distinguish one from the other.  They all have the same name and same Map property.  Yes, the extents MIGHT be different and you can interrogate the camera but how realistic is that?

This is where OpenView() and CloseViews() work well together. If you want to specify a specific Map or Layout View, you can first call CloseViews (with an option to close all or just maps or just layouts) and then call Layout or MapA.OpenView() and set your camera info accordingly.

I hope this makes sense.  Are you going to the Developer Summit?  I'd be happy to talk to you there.

Jeff

0 Kudos
PhilLarkin1
Occasional Contributor III

Hi @JeffBarrette 
Thanks for posting in the forum and creating the What's New documents.

I'm curious where the openView function is documented.

0 Kudos
JeffBarrette
Esri Regular Contributor

Map/Report/Layout.openView()

 

Jeff - Layout and arcpy.mp teams

0 Kudos
AndyAnderson
Occasional Contributor II

MapViews are often opened manually, not always by script. So there needs to be a way for a script to find them and work with them. Really, this is just a generalization of listLayouts.

Sadly, I cannot attend the DevSummit. Too busy teaching GIS Programming 🙂

—  Andy

0 Kudos