I want to be able to access and alter scale bar properties such as division values, division numbers, and units via Python. An ESRI staff member on the ArcObjects forum says it can't be done... yet.
+100 The ability to dynamically set the properties of a scale bar is paramount in managing advanced webprinting and geoprocessing. Currently we have to setup (and manage!) multiple mxds at slightly different scale settings to ensure that the scale bars and grids/graticules* are actually useful.
*the ability to set the grid/graticule division through arcpy.mapping is also sorely needed.
Just curious what the hold up is for ESRI to implement this? Seems like a request that has been around for awhile now.
I spoke to a couple of folks on the ESRI arcpy.mapping team about this at UC a couple of years ago. The party line seemed to be that ESRI didn't want to reinvent everything for python that was already available in ArcObjects. I keep hoping if we bug them enough it might happen though. I have to maintain a handful of templates with about 20 named scale bars each to get around this problem, which is kind of ridiculous if you ask me.
Hello everyone and thank you for your feedback! I missed this thread because it wasn't labelled arcpy.mp. We exposed Python CIM Access to be able to accommodate these finer grained requests. Please review this topic:
https://pro.arcgis.com/en/pro-app/latest/arcpy/mapping/python-cim-access.htm
You should be able to accomplish now using arcpy.mp and CIM access. Also in the pipeline on the Layout team (post 3.1) that you might find useful is we plan on adding scale thresholds to layout map surrounds elements so, for example, you can have multiple, stacked scalebars with different settings, scale will control visibility and if you sent the thresholds up correctly, just one scale bar would display at a time.
As for arcpy, here is a script from a downloadable sample that has 30 CIM snippets. I modified it slightly to also update divisions and subdivisions I saw mentioned in the thread. Here is a before and after scale bar.
Code sample:
p = arcpy.mp.ArcGISProject('current')
lyt = p.listLayouts('GreatLakes')[0]lyt_cim = lyt.getDefinition("V2") #Get the layout's CIM definition
#Iterate though all layout elements to find the ScaleBar element
for elm in lyt_cim.elements:
if elm.name == "Scale Bar":
#Change the number of divisions and subdivision
elm.divisions = 3
elm.subdivisions = 2
#Flip the scale bar so markers and labels appear below the line
elm.labelPosition = "Below"
elm.markPosition = "Below"
#Remove the first midpoint division label by labeling only divisions
elm.labelFrequency = "Divisions"lyt.setDefinition(lyt_cim) #Set the layout's CIM definition
The CIM samples can be located here:
https://esriurl.com/arcpy.mp/samples
Then scroll to the one called CIM Samples
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.