<?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: How do I create a new label class using arcpy? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/how-do-i-create-a-new-label-class-using-arcpy/m-p/1303773#M68052</link>
    <description>&lt;P&gt;Hi, have you finally solved problem with adding new label class?&lt;/P&gt;</description>
    <pubDate>Wed, 28 Jun 2023 06:52:02 GMT</pubDate>
    <dc:creator>peter_poti_sk</dc:creator>
    <dc:date>2023-06-28T06:52:02Z</dc:date>
    <item>
      <title>How do I create a new label class using arcpy?</title>
      <link>https://community.esri.com/t5/python-questions/how-do-i-create-a-new-label-class-using-arcpy/m-p/243840#M18943</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am using ArcPro 2.6 and I can modify existing label classes no problem. But what I want to do is to create a new label class using arcpy- I just cannot figure it out, what am I missing? All example’s I come across starts with listLabelClasses which assumes the class already exists.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 31 Jul 2020 01:01:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-do-i-create-a-new-label-class-using-arcpy/m-p/243840#M18943</guid>
      <dc:creator>Per_Åke_MattiasWallin</dc:creator>
      <dc:date>2020-07-31T01:01:52Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a new label class using arcpy?</title>
      <link>https://community.esri.com/t5/python-questions/how-do-i-create-a-new-label-class-using-arcpy/m-p/243841#M18944</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;From here&lt;/P&gt;&lt;P&gt;&lt;A class="link-titled" href="https://pro.arcgis.com/en/pro-app/arcpy/mapping/layer-class.htm" title="https://pro.arcgis.com/en/pro-app/arcpy/mapping/layer-class.htm"&gt;Layer—ArcGIS Pro | Documentation&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE style="color: #4c4c4c; background-color: #ffffff; border: 1px solid #cccccc; font-size: 0.875rem; margin-bottom: 1.55rem;"&gt;&lt;TBODY&gt;&lt;TR style="border-bottom: 1px solid #cccccc;"&gt;&lt;TD style="border-left: 1px solid #cccccc; border-right: 1px solid #cccccc; font-weight: 300; padding: 0.51667rem;"&gt;listLabelClasses ({wildcard})&lt;/TD&gt;&lt;TD style="border-left: 1px solid #cccccc; border-right: 1px solid #cccccc; font-weight: 300; padding: 0.51667rem;"&gt;&lt;P&gt;Returns a Python list of&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/arcpy/mapping/labelclass-class.htm" style="color: #0074b8; text-decoration: none;"&gt;LabelClass&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;objects in a layer.&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P style="color: #4c4c4c; background-color: #ffffff; margin-bottom: 1.55rem;"&gt;Which means you have to have something to create the labels from, and as you know...&lt;BR /&gt;&lt;BR /&gt;&lt;A class="link-titled" href="https://pro.arcgis.com/en/pro-app/arcpy/mapping/labelclass-class.htm" title="https://pro.arcgis.com/en/pro-app/arcpy/mapping/labelclass-class.htm"&gt;LabelClass—ArcGIS Pro | Documentation&lt;/A&gt;&lt;BR /&gt;with the warning&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P style="color: #4c4c4c; background-color: #ffffff; margin-bottom: 1.55rem;"&gt;Not all layers support labeling, so it is useful to test this ahead of time using the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class=""&gt;supports&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;method on the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/arcpy/mapping/layer-class.htm" style="color: #0074b8; text-decoration: none;"&gt;Layer&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;object. For example:&lt;/P&gt;&lt;DIV class=""&gt;&lt;PRE style="margin-bottom: 1.55rem;"&gt;&lt;CODE class="" style="color: #595959; background-color: #f8f8f8; border: 1px solid #efefef; font-size: 0.85em;"&gt;if lyr.supports("SHOWLABELS"):&lt;/CODE&gt;&lt;/PRE&gt;&lt;/DIV&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;where you can modify them.&lt;/P&gt;&lt;P&gt;But I don't know what you would use as a base except for an existing file&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 31 Jul 2020 01:49:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-do-i-create-a-new-label-class-using-arcpy/m-p/243841#M18944</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2020-07-31T01:49:22Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a new label class using arcpy?</title>
      <link>https://community.esri.com/t5/python-questions/how-do-i-create-a-new-label-class-using-arcpy/m-p/243842#M18945</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you for your reply Dan.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I was able to create a new label class using this:&lt;/P&gt;&lt;P&gt;# Create a new label class&lt;BR /&gt; new_label_class = arcpy.cim.CreateCIMObjectFromClassName('CIMLabelClass','V2')&lt;BR /&gt; new_label_class.name = 'Class 2'&lt;BR /&gt; cim_industry.labelClasses.append(new_label_class)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However...&amp;nbsp; whenever I try to use the layer that I created the new label class on it crashes ArcPro so something gets corrupted...&amp;nbsp; which they do wanrn about here,&amp;nbsp;&lt;A class="link-titled" href="https://pro.arcgis.com/en/pro-app/arcpy/mapping/python-cim-access.htm#ESRI_SECTION1_20A05482BA6249D09353BF7CA185C1AD" title="https://pro.arcgis.com/en/pro-app/arcpy/mapping/python-cim-access.htm#ESRI_SECTION1_20A05482BA6249D09353BF7CA185C1AD"&gt;Python CIM access—ArcGIS Pro | Documentation&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 31 Jul 2020 23:43:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-do-i-create-a-new-label-class-using-arcpy/m-p/243842#M18945</guid>
      <dc:creator>Per_Åke_MattiasWallin</dc:creator>
      <dc:date>2020-07-31T23:43:26Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a new label class using arcpy?</title>
      <link>https://community.esri.com/t5/python-questions/how-do-i-create-a-new-label-class-using-arcpy/m-p/243843#M18946</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I just noticed that there is a feature request&amp;nbsp;&lt;A href="https://community.esri.com/ideas/6533" target="_blank"&gt;https://community.esri.com/ideas/6533&lt;/A&gt;&amp;nbsp; from 2012 with 9 votes...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 22 Jun 2021 08:26:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-do-i-create-a-new-label-class-using-arcpy/m-p/243843#M18946</guid>
      <dc:creator>Per_Åke_MattiasWallin</dc:creator>
      <dc:date>2021-06-22T08:26:13Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a new label class using arcpy?</title>
      <link>https://community.esri.com/t5/python-questions/how-do-i-create-a-new-label-class-using-arcpy/m-p/243844#M18947</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am also noticing the same thing. I use &lt;STRONG style="background-color: #ffffff; "&gt;arcpy.cim.CreateCIMObjectFromClassName('CIMLabelClass','V2')&amp;nbsp;&lt;/STRONG&gt;&lt;SPAN style="background-color: #ffffff;"&gt;and then append it into the list of label classes. When I go to interact with the new label class in the GUI ArcPro immediately crashes.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Nov 2020 02:04:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-do-i-create-a-new-label-class-using-arcpy/m-p/243844#M18947</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2020-11-11T02:04:37Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a new label class using arcpy?</title>
      <link>https://community.esri.com/t5/python-questions/how-do-i-create-a-new-label-class-using-arcpy/m-p/1031797#M60175</link>
      <description>&lt;P&gt;It may be easier to try the&amp;nbsp; arcpy.cim.CIMLabelClass() to create a new label class&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Essentially I think you can get your layer object and export out a version of the cim object like this.&lt;/P&gt;&lt;P&gt;cimObject = LayerObj.getDefinition(‘v2’)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;From here I would use arcpy.cim.CIMLabelClass() to create a new label placement object and set all of the properties to your liking.&lt;/P&gt;&lt;P&gt;Then append this new object to the cimObject label class list.&lt;/P&gt;&lt;P&gt;Something like&amp;nbsp; cimObject.labelClasses.append(new label class obj)&lt;/P&gt;&lt;P&gt;Check the cimObject.labelClasses to see if its in there.&lt;/P&gt;&lt;P&gt;Then go ahead and set its definition like this&lt;/P&gt;&lt;P&gt;LayerObj.setDefinition(cimObject)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This should work, I don’t think you will see it in the Pro interface under the labelling tab but the label class should be added to your layer object.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Mar 2021 06:33:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-do-i-create-a-new-label-class-using-arcpy/m-p/1031797#M60175</guid>
      <dc:creator>Nicholas_G</dc:creator>
      <dc:date>2021-03-02T06:33:02Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a new label class using arcpy?</title>
      <link>https://community.esri.com/t5/python-questions/how-do-i-create-a-new-label-class-using-arcpy/m-p/1303773#M68052</link>
      <description>&lt;P&gt;Hi, have you finally solved problem with adding new label class?&lt;/P&gt;</description>
      <pubDate>Wed, 28 Jun 2023 06:52:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-do-i-create-a-new-label-class-using-arcpy/m-p/1303773#M68052</guid>
      <dc:creator>peter_poti_sk</dc:creator>
      <dc:date>2023-06-28T06:52:02Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a new label class using arcpy?</title>
      <link>https://community.esri.com/t5/python-questions/how-do-i-create-a-new-label-class-using-arcpy/m-p/1312811#M68270</link>
      <description>&lt;P&gt;I have figured out a way to bypass the corruption of the CIM definition when attempting to create a new label class with ArcPy CIM.&amp;nbsp; To test this out, you can use any layer those default class is named "Class 1." Instead of using &lt;SPAN&gt;&lt;FONT face="andale mono,times" color="#008000"&gt;arcpy.cim.CreateCIMObjectFromClassName('CIMLabelClass','V2') &lt;/FONT&gt;or&amp;nbsp;&lt;FONT face="andale mono,times" color="#008000"&gt;arcpy.cim.CIMLabelClass()&lt;/FONT&gt; as suggested by other users, I used &lt;FONT face="andale mono,times" color="#008000"&gt;cimObject.labelClasses.copy()&lt;/FONT&gt;.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;The code to try out is below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy

p = arcpy.mp.ArcGISProject('CURRENT')
m = p.listMaps('Map')[0]
layer = m.listLayers("Your Layer Name Here")[0]
cimObject = layer.getDefinition('V2')
lblClasses = cimObject.labelClasses
    
for lblClass in lblClasses:
    if lblClass.name == "Class 1":
        nlc_index = cimObject.labelClasses.index(lblClass)
        lblClass_copy = cimObject.labelClasses.copy()[nlc_index]
        cimObject.labelClasses.append(lblClass_copy)
        layer.setDefinition(cimObject)
        break

cimObject = layer.getDefinition('V2')
lblClasses = cimObject.labelClasses        
        
for lblClass in lblClasses:
    if lblClass.name == "Class 1":
        nlc_index = cimObject.labelClasses.index(lblClass)
        if nlc_index != 0:
            lblClass.name = "Dummy"
            layer.setDefinition(cimObject)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope this helps other users!&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jul 2023 20:17:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-do-i-create-a-new-label-class-using-arcpy/m-p/1312811#M68270</guid>
      <dc:creator>DestinyKelley1</dc:creator>
      <dc:date>2023-07-27T20:17:53Z</dc:date>
    </item>
  </channel>
</rss>

