I'm programmatically creating a map series layout in ArcGIS Pro using CIM. I can enable the map series, set the map frame, layer, name & sort fields and set the extent options any way I choose via code. However, I cannot find a property to set the Scale under Center and Maintain Scale. See image.
I can't find 'Scale' in the documentation. There is 'scaleRounding', but that only affects 'Round up scale to nearest ##' under Best Fit Extent.
This is my code. It works. I just can't change the Scale...
def enable_plan_view_map_series(aprx, map_name, layer_name, layout_name, map_frame_name, start_page):
layer_URI, layout, layout_cim = get_layer_cim_definition(aprx, map_name, layer_name, layout_name)
#Create CIM Spatial Map Series Object and populate its properties
ms = arcpy.cim.CreateCIMObjectFromClassName('CIMSpatialMapSeries', 'V3')
ms.enabled = True
ms.mapFrameName = map_frame_name
ms.startingPageNumber = start_page
ms.currentPageID = start_page
ms.indexLayerURI = layer_URI #Index layer URI from Layer's CIM
ms.nameField = "Sheet_Name"
ms.sortField = "Sheet_Num"
ms.sortAscending = True
ms.extentOptions = "ExtentCenter"
layout_cim.mapSeries = ms #Set new map series to layout
layout.setDefinition(layout_cim) #Set the Layout's CIM definition
#Force a refresh of the layout and its associated panes
layout_cim = layout.getDefinition('V3')
layout.setDefinition(layout_cim)
Thanks, any help would be greatly appreciated.
Solved! Go to Solution.
Hello @JasonBennett , I just tried the following and it works for me.
I find the best approach to learning where stuff is persisted in the CIM is to create a before and after result that can be compared using an application that shows differences (e.g. WinMerge). So what I did first was export my Best Fit map series to a PAGX file.
Then I changed my options to use Center and Maintain Scale and exported to a PAGX again with a different name.
I use WinMerge to compare the two text files (tip, if you rename the *.pagx to *.json, the formatting may look cleaner). When I compare the differences, I see that the map series CIM has a "extentOptions" property and I changed it from "BestFit" to the "ExtentCenter" enum. Then I updated the map series mapframe camera scale property.
Here is the code I used to make the changed to my map series.
#Reference project and layout
p = arcpy.mp.ArcGISProject('current')
lyt = p.listLayouts('*_MS')[0]
#First, change the map series extent option
ms = lyt.mapSeries
ms_cim = ms.getDefinition('V3')
ms_cim.extentOptions = 'ExtentCenter' #Center and Maintain Scale
ms.setDefinition(ms_cim)
#Now change the scale of the map frame (via the camera object)
mf = lyt.listElements('mapframe_element', 'Map Frame')[0]
cam = mf.camera.scale
cam.scale = 5000000
I hope this was helpful,
Jeff - arcpy.mp team
Hello @JasonBennett , I just tried the following and it works for me.
I find the best approach to learning where stuff is persisted in the CIM is to create a before and after result that can be compared using an application that shows differences (e.g. WinMerge). So what I did first was export my Best Fit map series to a PAGX file.
Then I changed my options to use Center and Maintain Scale and exported to a PAGX again with a different name.
I use WinMerge to compare the two text files (tip, if you rename the *.pagx to *.json, the formatting may look cleaner). When I compare the differences, I see that the map series CIM has a "extentOptions" property and I changed it from "BestFit" to the "ExtentCenter" enum. Then I updated the map series mapframe camera scale property.
Here is the code I used to make the changed to my map series.
#Reference project and layout
p = arcpy.mp.ArcGISProject('current')
lyt = p.listLayouts('*_MS')[0]
#First, change the map series extent option
ms = lyt.mapSeries
ms_cim = ms.getDefinition('V3')
ms_cim.extentOptions = 'ExtentCenter' #Center and Maintain Scale
ms.setDefinition(ms_cim)
#Now change the scale of the map frame (via the camera object)
mf = lyt.listElements('mapframe_element', 'Map Frame')[0]
cam = mf.camera.scale
cam.scale = 5000000
I hope this was helpful,
Jeff - arcpy.mp team
I never thought to compare changes like that! This makes it so much easier to what I'm looking for. Thanks for your help. This worked perfectly!
@JasonBennett I'm glad it worked. Comparing the before and after is super useful especially if you minimize the changes to the absolute necessary steps between saves. Sometime you might see new objects are introduced and that is when you would might need to use CreateCIMObjectFromClassName. It is covered in this topic: https://pro.arcgis.com/en/pro-app/latest/arcpy/mapping/python-cim-access.htm
Jeff