aprx.activeView (MapView or Layout)

324
9
Jump to solution
11-10-2020 09:44 AM
ChrisHolmes
Occasional Contributor III

I'm stumped. The following documentation says activeView will return the active MapView or Layout. I've searched high and low trying to find code to use which will tell me If the "active view" is a map or a layout but am having zero luck.

Any insight appreciated.

Thanks! 

MapView—ArcGIS Pro | Documentation 

Reply
0 Kudos
1 Solution

Accepted Solutions
JoshuaBixby
MVP Esteemed Contributor

Just check the type of the object or class inheritance:

>>> type(aprx.activeView)
<class 'arcpy._mp.Layout'>
>>> isinstance(aprx.activeView, arcpy._mp.Layout)
True

View solution in original post

9 Replies
JoshuaBixby
MVP Esteemed Contributor

Just check the type of the object or class inheritance:

>>> type(aprx.activeView)
<class 'arcpy._mp.Layout'>
>>> isinstance(aprx.activeView, arcpy._mp.Layout)
True

View solution in original post

ChrisHolmes
Occasional Contributor III

Thanks so much Joshua!

Reply
0 Kudos
JoshuaBixby
MVP Esteemed Contributor

If my response answered your question, please mark it Correct to cloud out the question.

Reply
0 Kudos
ChrisHolmes
Occasional Contributor III

Just did, thanks. Had been away from my computer...

Reply
0 Kudos
ChrisHolmes
Occasional Contributor III

Once I've got the activeView how do I grab the name of the MapView or Layout?

Reply
0 Kudos
JoshuaBixby
MVP Esteemed Contributor

view = aprx.activeView

name = view.map.name

Reply
0 Kudos
ChrisHolmes
Occasional Contributor III

ah .map.name

I was trying just .name

Suppose it makes sense when you think about it though. 

Are these properties documented anywhere? Then only documentation I could find about activeView is basicallly the page I linked in the original question. 

Thanks!

Reply
0 Kudos
JoshuaBixby
MVP Esteemed Contributor

It is all in the documentation.  The MapView—ArcGIS Pro | Documentation documentation shows a "map" property that returns a Map—ArcGIS Pro | Documentation object that has a "name" property.

You just need to follow the bread crumbs.

ChrisHolmes
Occasional Contributor III

True. So I came up with the following:

When the active view is a map it displays the map name and when the active view is a layout it displays the layout name.

I was thinking that getting the name of the active layout should be mv.layout.name but no it's just mv.name

Logically it doesn't really make sense to me, but it works and I'm happy with that.

Thanks for all your help

Reply
0 Kudos