Arcpy set extent of map with CIM

917
5
12-02-2021 05:28 AM
XavierRouxRacine1
New Contributor

Hello, 

I try to set the extent of a map in a aprx by setting the definition of this one. I want to set by setting the defautExtent parameter with a CIM object. Here is my code I want to proceed but it is unsucessful : 

 

p = arcpy.mp.ArcGISProject('current')
m = p.listMaps('*')[0]

m_cim = m.getDefinition('V2') #Get the Map's CIM definition

 

extent = m.listLayers('*')[0].getExtent()


CimExtent = arcpy.cim.CreateCIMObjectFromClassName('CIMExtentIndicator', 'V2')
CimExtent .values = extent 
m_cim.defaultExtent = RGBColor

m.setDefinition(m_cim)

p.save()

 

Does the CIMExtentIndicator is the good object type to set the extent of the map. 

 

Thank you

0 Kudos
5 Replies
DanPatterson
MVP Esteemed Contributor

apparently from the "camera"

Solved: ArcGIS Pro: Set a Map's extent from a layer's exte... - Esri Community


... sort of retired...
0 Kudos
XavierRouxRacine1
New Contributor

Thank you, but I want to apply the set extent on the map view directly. I am able to do it with the 'activeView' when I got the aprx open, but is it possible without using the activeView. So that's why I wanted to pass by the setDefinition of the map object. I don't have layout in my aprx. 

 

Thank you

0 Kudos
DanPatterson
MVP Esteemed Contributor

I don't see anything in either the mapview of map or CIM function documentation, but I assume you have checked those as well


... sort of retired...
0 Kudos
ZhongyuYang
New Contributor II

Hi XavierRouxRacine1, 

Have you figured this out? I have the same question as you.

Thanks,

Zhongyu

0 Kudos
mody_buchbinder
Occasional Contributor III

I discussed it with esri support lately.

The setExtent works on MapView only so there is  no way to do it on an aprx that is not current.

Using the CIM to do it can be a workaround if somebody can find the correct way to do it.

0 Kudos