<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Modifying Scale Bar with CIM in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/modifying-scale-bar-with-cim/m-p/1621660#M74329</link>
    <description>&lt;P&gt;This may be cheating, but rather than dealing with all that I've occasionally resorted to:&lt;/P&gt;&lt;P&gt;1. Manually creating an element how I want it&lt;/P&gt;&lt;P&gt;2. Exporting the layout file the element lives in, then opening the file as text&lt;/P&gt;&lt;P&gt;4. Copying the definition for the entire element&amp;nbsp;&lt;/P&gt;&lt;P&gt;5. Adding it to a script like this:&lt;/P&gt;&lt;P&gt;import json&lt;/P&gt;&lt;P&gt;#create a new element, I did this with a text box&lt;BR /&gt;loc_callout = aprx.createTextElement (blah arguments blah)&lt;/P&gt;&lt;P&gt;loc_callout_cim = loc_callout.getDefinition ('V3')&lt;/P&gt;&lt;P&gt;callout_json = ''' {&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;"type" : "CIMGraphicElement",&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;......all the copied JSON to the end of the element here.....&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;}'''&lt;/P&gt;&lt;P&gt;# Parse JSON into Python dictionary&lt;BR /&gt;callout_dict = json.loads(callout_json)&lt;BR /&gt;&lt;BR /&gt;# Assign to the text box/callout&amp;nbsp;&lt;BR /&gt;loc_callout_cim = callout_dict&lt;BR /&gt;&lt;BR /&gt;loc_callout.setDefinition(loc_callout_cim)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 06 Jun 2025 20:47:14 GMT</pubDate>
    <dc:creator>MaggieT</dc:creator>
    <dc:date>2025-06-06T20:47:14Z</dc:date>
    <item>
      <title>Modifying Scale Bar with CIM</title>
      <link>https://community.esri.com/t5/python-questions/modifying-scale-bar-with-cim/m-p/1614800#M74186</link>
      <description>&lt;P&gt;I'm trying to automate the creation of a layout that includes a scale bar.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want the size determined by the division value (2000 when the layout is first created), so I need to set the fitting strategy property to "Adjust width". This is what it would look like ideally:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="MaggieT_0-1747257378446.png" style="width: 245px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/132263i95EB909866DA70B8/image-dimensions/245x55?v=v2" width="245" height="55" role="button" title="MaggieT_0-1747257378446.png" alt="MaggieT_0-1747257378446.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I'm able to make a scale bar, but I'm having a hard time setting it up properly. Currently it still has "Adjust division value" as the fitting strategy, and is in miles. In fact &lt;STRONG&gt;nothing&lt;/STRONG&gt; is updating after the line that originally creates the bar. Looks like this:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="MaggieT_2-1747258334869.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/132281i3A938D2584941908/image-size/medium?v=v2&amp;amp;px=400" role="button" title="MaggieT_2-1747258334869.png" alt="MaggieT_2-1747258334869.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;This is what I have so far:&lt;/P&gt;&lt;P&gt;sbName = 'Double Alternating Scale Bar 1'&lt;BR /&gt;sbStyle = aprx.listStyleItems('ArcGIS 2D', 'Scale_bar', sbName)[0]&lt;/P&gt;&lt;P&gt;sb = lyt.createMapSurroundElement(geometry = arcpy.Point(1, 9), mapsurround_type = 'Scale_bar', mapframe = main_map_frame, style_item = sbStyle, name = 'New Scale Bar')&lt;/P&gt;&lt;P&gt;lyt_cim = lyt.getDefinition('V3')&lt;BR /&gt;for elm in lyt_cim.elements:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; if elm.name == 'New Scale Bar':&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; elm.FittingStrategy = "AdjustWidth"&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; elm.Division = 2000&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; elm.Divisions = 1&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; elm.Subdivisions = 1&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; elm.MarkFrequency = "DivisionsAndFirstMidpoint"&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; elm.MarkPosition = "AboveBar"&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; elm.Units = "Feet"&lt;BR /&gt;lyt.setDefinition(lyt_cim)&lt;BR /&gt;aprx.save()&lt;/P&gt;&lt;P&gt;I'm referring mostly to these sources:&lt;/P&gt;&lt;P&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/3.3/arcpy/mapping/mapsurroundelement-class.htm" target="_blank"&gt;https://pro.arcgis.com/en/pro-app/3.3/arcpy/mapping/mapsurroundelement-class.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/sdk/api-reference/topic4880.html" target="_blank"&gt;https://pro.arcgis.com/en/pro-app/latest/sdk/api-reference/topic4880.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 May 2025 21:50:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/modifying-scale-bar-with-cim/m-p/1614800#M74186</guid>
      <dc:creator>MaggieT</dc:creator>
      <dc:date>2025-05-14T21:50:20Z</dc:date>
    </item>
    <item>
      <title>Re: Modifying Scale Bar with CIM</title>
      <link>https://community.esri.com/t5/python-questions/modifying-scale-bar-with-cim/m-p/1614809#M74187</link>
      <description>&lt;P&gt;You're on the right track.&lt;/P&gt;&lt;P&gt;I've found better success with using normal arcpy.mp as much as possible to get the element I want, THEN getting its definition.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;sb_cim = sb.getDefinition('V3')
sb_cim.fittingStrategy ="AdjustFrame"
sb_cim.division = 2000
sb_cim.divisions = 1
sb_cim.subdivisions = 1
sb_cim.markFrequency = "DivisionsAndFirstMidpoint"
sb_cim.markPosition = "AboveBar"
sb_cim.units = "Feet"
sb_cim.unitLabel = "Feet"

sb.setDefinition(sb_cim)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;CIM is super tricky and is a great example of how naming in one space does not reflect naming behind the scenes. For example, what we see as "Adjust Width" is actually "AdjustFrame".&lt;/P&gt;&lt;P&gt;This page is a great resource (although not infallible)&amp;nbsp;&lt;A href="https://github.com/Esri/cim-spec/blob/809fb365d8d204d1fbdc51b3fab5bd17d88de2d1/docs/v3" target="_blank" rel="noopener"&gt;https://github.com/Esri/cim-spec/blob/809fb365d8d204d1fbdc51b3fab5bd17d88de2d1/docs/v3&amp;nbsp;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Go to the general idea of what you want (Layout element--&amp;gt; Layout page), then search for what you want. I looked for "ScaleBar", which took me &lt;A href="https://github.com/Esri/cim-spec/blob/809fb365d8d204d1fbdc51b3fab5bd17d88de2d1/docs/v3/CIMLayout.md#cimscalebar" target="_blank" rel="noopener"&gt;here&lt;/A&gt;. I then noticed that there was a link in the description for fittingStrategy to a l&lt;A href="https://github.com/Esri/cim-spec/blob/809fb365d8d204d1fbdc51b3fab5bd17d88de2d1/docs/v3/CIMLayout.md#enumeration-scalebarfittingstrategy" target="_blank" rel="noopener"&gt;ist of all acceptable values&lt;/A&gt;. (idk why these pictures are so blurry, sorry)&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="AlfredBaldenweck_2-1747262244055.png" style="width: 993px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/132286i71408DAE58D87D34/image-size/medium?v=v2&amp;amp;px=400" role="button" title="AlfredBaldenweck_2-1747262244055.png" alt="AlfredBaldenweck_2-1747262244055.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="AlfredBaldenweck_3-1747262254478.png" style="width: 746px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/132287iB97361DC07246556/image-size/medium?v=v2&amp;amp;px=400" role="button" title="AlfredBaldenweck_3-1747262254478.png" alt="AlfredBaldenweck_3-1747262254478.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 May 2025 22:38:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/modifying-scale-bar-with-cim/m-p/1614809#M74187</guid>
      <dc:creator>AlfredBaldenweck</dc:creator>
      <dc:date>2025-05-14T22:38:05Z</dc:date>
    </item>
    <item>
      <title>Re: Modifying Scale Bar with CIM</title>
      <link>https://community.esri.com/t5/python-questions/modifying-scale-bar-with-cim/m-p/1615033#M74189</link>
      <description>&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;Those resources are very helpful.&lt;/P&gt;&lt;P&gt;Your script got it most of the rest of the way there, the only thing I had to change was&amp;nbsp;setting the units equal to {'uwkid': 9002}&amp;nbsp;&lt;/P&gt;&lt;P&gt;I couldn't figure out how to format that part correctly with the WKID value so I just manually set the units in the scale bar and did this to check what it looked like:&lt;/P&gt;&lt;P&gt;sb_cim = sb.getDefinition('V3')&lt;/P&gt;&lt;P&gt;sb_cim.units&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 May 2025 15:44:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/modifying-scale-bar-with-cim/m-p/1615033#M74189</guid>
      <dc:creator>MaggieT</dc:creator>
      <dc:date>2025-05-15T15:44:21Z</dc:date>
    </item>
    <item>
      <title>Re: Modifying Scale Bar with CIM</title>
      <link>https://community.esri.com/t5/python-questions/modifying-scale-bar-with-cim/m-p/1615186#M74190</link>
      <description>&lt;P&gt;Glad it worked out! I had to do the same thing to figure out the fitting strategy.&lt;/P&gt;</description>
      <pubDate>Thu, 15 May 2025 20:18:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/modifying-scale-bar-with-cim/m-p/1615186#M74190</guid>
      <dc:creator>AlfredBaldenweck</dc:creator>
      <dc:date>2025-05-15T20:18:12Z</dc:date>
    </item>
    <item>
      <title>Re: Modifying Scale Bar with CIM</title>
      <link>https://community.esri.com/t5/python-questions/modifying-scale-bar-with-cim/m-p/1617835#M74260</link>
      <description>&lt;P&gt;The CIM API in arcpy is atrocious. I've done a few personal hacks to make it properly typed, but it's a pain to maintain and is technically an unsupported version of arcpy.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hopefully they implement my request for CIM type hinting and literals soon. My 3+ years of hounding them had finally got them to add literals for mp, da, and some arcpy.Parameter attributes lol. CIM should be next, but the whole module is autogenerated by some archaic internal Python 2 script or god forbid bash script. So that one will require either manual maintenance or a total rewrite of that CI/CD pipeline that builds the CIM module.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What's nice about Python 3 is that the typing system doesn't really care about recursive typing (since they aren't evaluated at run time), so you don't need to create a recursive class definition anymore and can instead inject a class into another class that also has an attribute of that original class (something common in json, but not common in strictly typed languages)&lt;/P&gt;</description>
      <pubDate>Fri, 23 May 2025 03:08:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/modifying-scale-bar-with-cim/m-p/1617835#M74260</guid>
      <dc:creator>HaydenWelch</dc:creator>
      <dc:date>2025-05-23T03:08:02Z</dc:date>
    </item>
    <item>
      <title>Re: Modifying Scale Bar with CIM</title>
      <link>https://community.esri.com/t5/python-questions/modifying-scale-bar-with-cim/m-p/1617895#M74267</link>
      <description>&lt;P&gt;I've been meaning to bug someone about how a certain property enumerated in the CIM documentation linked above is returned as a "property" object with no value, even though the documentation says there should be a value and the CIM viewer addin clearly shows the value I'm looking for.&lt;/P&gt;</description>
      <pubDate>Fri, 23 May 2025 14:14:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/modifying-scale-bar-with-cim/m-p/1617895#M74267</guid>
      <dc:creator>AlfredBaldenweck</dc:creator>
      <dc:date>2025-05-23T14:14:26Z</dc:date>
    </item>
    <item>
      <title>Re: Modifying Scale Bar with CIM</title>
      <link>https://community.esri.com/t5/python-questions/modifying-scale-bar-with-cim/m-p/1621660#M74329</link>
      <description>&lt;P&gt;This may be cheating, but rather than dealing with all that I've occasionally resorted to:&lt;/P&gt;&lt;P&gt;1. Manually creating an element how I want it&lt;/P&gt;&lt;P&gt;2. Exporting the layout file the element lives in, then opening the file as text&lt;/P&gt;&lt;P&gt;4. Copying the definition for the entire element&amp;nbsp;&lt;/P&gt;&lt;P&gt;5. Adding it to a script like this:&lt;/P&gt;&lt;P&gt;import json&lt;/P&gt;&lt;P&gt;#create a new element, I did this with a text box&lt;BR /&gt;loc_callout = aprx.createTextElement (blah arguments blah)&lt;/P&gt;&lt;P&gt;loc_callout_cim = loc_callout.getDefinition ('V3')&lt;/P&gt;&lt;P&gt;callout_json = ''' {&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;"type" : "CIMGraphicElement",&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;......all the copied JSON to the end of the element here.....&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;}'''&lt;/P&gt;&lt;P&gt;# Parse JSON into Python dictionary&lt;BR /&gt;callout_dict = json.loads(callout_json)&lt;BR /&gt;&lt;BR /&gt;# Assign to the text box/callout&amp;nbsp;&lt;BR /&gt;loc_callout_cim = callout_dict&lt;BR /&gt;&lt;BR /&gt;loc_callout.setDefinition(loc_callout_cim)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 06 Jun 2025 20:47:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/modifying-scale-bar-with-cim/m-p/1621660#M74329</guid>
      <dc:creator>MaggieT</dc:creator>
      <dc:date>2025-06-06T20:47:14Z</dc:date>
    </item>
    <item>
      <title>Re: Modifying Scale Bar with CIM</title>
      <link>https://community.esri.com/t5/python-questions/modifying-scale-bar-with-cim/m-p/1621826#M74337</link>
      <description>&lt;P&gt;That is definitely cheating lol but it works so it isn't.&lt;/P&gt;</description>
      <pubDate>Mon, 09 Jun 2025 14:10:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/modifying-scale-bar-with-cim/m-p/1621826#M74337</guid>
      <dc:creator>AlfredBaldenweck</dc:creator>
      <dc:date>2025-06-09T14:10:11Z</dc:date>
    </item>
  </channel>
</rss>

