<?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 Unable to save label expression in arcpy module 3.3 in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/unable-to-save-label-expression-in-arcpy-module-3/m-p/1540922#M72918</link>
    <description>&lt;P&gt;Hello everyone,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to write code that saves label expressions before performing an Add Join, as the join process messes up the expressions. After the Add Join is completed, I plan to restore the label expressions.&lt;/P&gt;&lt;P&gt;We are on the verge of migrating from the arcpy.mapping module to the arcpy.mp module. According to the documentation, it seems that label functionality has been changed to the LabelClass object. I can confirm that my layer supports label expressions, as shown by the command lyr.supports("SHOWLABELS"). However, when the code reaches the part where a setDefinition is implemented, I get an error message.&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;"ArcGIS Pro caused an error and it causes script to break".&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;code used in arcpy.mapping (just of reference):&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;lblExpression = opplan_outline.labelClasses[0].expression&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;performing Add join&lt;BR /&gt;&lt;BR /&gt;# retrieving label expression&lt;BR /&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;opplan_outline.labelClasses[0].expression = lblExpression&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;Code I am trying to convert in arcpy.mp module&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;opplan_outline &lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt; map_obj.&lt;/SPAN&gt;&lt;SPAN&gt;listLayers&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN&gt;Opplan_Layer_Outline&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;SPAN&gt;[&lt;/SPAN&gt;&lt;SPAN&gt;0&lt;/SPAN&gt;&lt;SPAN&gt;]&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;label_defs = []&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;if opplan_outline.supports("SHOWLABELS"):&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp; for lblClass in opplan_outline.listLabelClasses():&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; label_defs.append(lblClass.getDefinition("V3"))&lt;BR /&gt;&lt;BR /&gt;performing add join&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;if opplan_outline.supports("SHOWLABELS"):&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;for i, lblClass in enumerate(opplan_outline.listLabelClasses()):&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; lblClass.setDefinition(label_defs[i])&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;Error message is ArcGIS Application has stopped working. even though Arcgis Pro is not open. And I have also figured out that the issue lies in when the set definition comes into place.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="PrayagShah_0-1726841681337.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/115569iE8E578C99C36FE63/image-size/medium?v=v2&amp;amp;px=400" role="button" title="PrayagShah_0-1726841681337.png" alt="PrayagShah_0-1726841681337.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you everyone in advance.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 20 Sep 2024 14:16:07 GMT</pubDate>
    <dc:creator>PrayagShah</dc:creator>
    <dc:date>2024-09-20T14:16:07Z</dc:date>
    <item>
      <title>Unable to save label expression in arcpy module 3.3</title>
      <link>https://community.esri.com/t5/python-questions/unable-to-save-label-expression-in-arcpy-module-3/m-p/1540922#M72918</link>
      <description>&lt;P&gt;Hello everyone,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to write code that saves label expressions before performing an Add Join, as the join process messes up the expressions. After the Add Join is completed, I plan to restore the label expressions.&lt;/P&gt;&lt;P&gt;We are on the verge of migrating from the arcpy.mapping module to the arcpy.mp module. According to the documentation, it seems that label functionality has been changed to the LabelClass object. I can confirm that my layer supports label expressions, as shown by the command lyr.supports("SHOWLABELS"). However, when the code reaches the part where a setDefinition is implemented, I get an error message.&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;"ArcGIS Pro caused an error and it causes script to break".&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;code used in arcpy.mapping (just of reference):&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;lblExpression = opplan_outline.labelClasses[0].expression&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;performing Add join&lt;BR /&gt;&lt;BR /&gt;# retrieving label expression&lt;BR /&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;opplan_outline.labelClasses[0].expression = lblExpression&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;Code I am trying to convert in arcpy.mp module&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;opplan_outline &lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt; map_obj.&lt;/SPAN&gt;&lt;SPAN&gt;listLayers&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN&gt;Opplan_Layer_Outline&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;SPAN&gt;[&lt;/SPAN&gt;&lt;SPAN&gt;0&lt;/SPAN&gt;&lt;SPAN&gt;]&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;label_defs = []&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;if opplan_outline.supports("SHOWLABELS"):&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp; for lblClass in opplan_outline.listLabelClasses():&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; label_defs.append(lblClass.getDefinition("V3"))&lt;BR /&gt;&lt;BR /&gt;performing add join&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;if opplan_outline.supports("SHOWLABELS"):&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;for i, lblClass in enumerate(opplan_outline.listLabelClasses()):&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; lblClass.setDefinition(label_defs[i])&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;Error message is ArcGIS Application has stopped working. even though Arcgis Pro is not open. And I have also figured out that the issue lies in when the set definition comes into place.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="PrayagShah_0-1726841681337.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/115569iE8E578C99C36FE63/image-size/medium?v=v2&amp;amp;px=400" role="button" title="PrayagShah_0-1726841681337.png" alt="PrayagShah_0-1726841681337.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you everyone in advance.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Sep 2024 14:16:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/unable-to-save-label-expression-in-arcpy-module-3/m-p/1540922#M72918</guid>
      <dc:creator>PrayagShah</dc:creator>
      <dc:date>2024-09-20T14:16:07Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to save label expression in arcpy module 3.3</title>
      <link>https://community.esri.com/t5/python-questions/unable-to-save-label-expression-in-arcpy-module-3/m-p/1541725#M72922</link>
      <description>&lt;P&gt;Have you tried using V2 as the CIM definition? I haven't worked with Arcmap at all really, but I know the CIM version has changed a lot and it could be an issue with that.&lt;/P&gt;
&lt;P&gt;Otherwise you're stuck in implementation struggles and might have to manually port the CIM defs over one attribute at a time.&lt;/P&gt;</description>
      <pubDate>Tue, 24 Sep 2024 12:42:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/unable-to-save-label-expression-in-arcpy-module-3/m-p/1541725#M72922</guid>
      <dc:creator>HaydenWelch</dc:creator>
      <dc:date>2024-09-24T12:42:03Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to save label expression in arcpy module 3.3</title>
      <link>https://community.esri.com/t5/python-questions/unable-to-save-label-expression-in-arcpy-module-3/m-p/1548610#M73022</link>
      <description>&lt;P&gt;It's not possible to answer this question as you do not show what you do at the line "&lt;SPAN&gt;performing add join". I'm guessing that what ever you are doing there is creating a corrupted&amp;nbsp;definition object which is the input to lblClass.setDefinition() and causes the script to catastrophically fail. I believe a limitation of accessing CIM is that there is no validation of the parameter, unlike tools you call in arcpy. So if you are not super careful in how you alter the definition object then you feed into CIM something that syntactically invalid and having by-passed any sort of validation you kill the script/application.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Oct 2024 11:51:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/unable-to-save-label-expression-in-arcpy-module-3/m-p/1548610#M73022</guid>
      <dc:creator>DuncanHornby</dc:creator>
      <dc:date>2024-10-15T11:51:16Z</dc:date>
    </item>
  </channel>
</rss>

