<?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 Labeling with python in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/labeling-with-python/m-p/133858#M10458</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am trying to give features labels with python code.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here is the code I am using:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;&amp;gt;&amp;gt;&amp;gt; import arcpy
... mxd = arcpy.mapping.MapDocument("CURRENT") 
... layer = arcpy.mapping.ListLayers(mxd, "")[0] 
... if layer.supports("LABELCLASSES"):
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for lblclass in layer.labelClasses:
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lblclass.showClassLabels = True
... lblclass.expression = "[type]"
... layer.showLabels = True
... arcpy.RefreshActiveView()
... &lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;and I get this error:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Runtime error &amp;lt;type 'exceptions.NameError'&amp;gt;: name 'lblclass' is not defined&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I thought this worked once, but not anymore..&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Do I have to define "lblclass"??&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you could give me some help, I'd really appreciate it, thanks!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 02 Sep 2013 01:22:14 GMT</pubDate>
    <dc:creator>HitomiMaezawa1</dc:creator>
    <dc:date>2013-09-02T01:22:14Z</dc:date>
    <item>
      <title>Labeling with python</title>
      <link>https://community.esri.com/t5/python-questions/labeling-with-python/m-p/133858#M10458</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am trying to give features labels with python code.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here is the code I am using:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;&amp;gt;&amp;gt;&amp;gt; import arcpy
... mxd = arcpy.mapping.MapDocument("CURRENT") 
... layer = arcpy.mapping.ListLayers(mxd, "")[0] 
... if layer.supports("LABELCLASSES"):
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for lblclass in layer.labelClasses:
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lblclass.showClassLabels = True
... lblclass.expression = "[type]"
... layer.showLabels = True
... arcpy.RefreshActiveView()
... &lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;and I get this error:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Runtime error &amp;lt;type 'exceptions.NameError'&amp;gt;: name 'lblclass' is not defined&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I thought this worked once, but not anymore..&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Do I have to define "lblclass"??&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you could give me some help, I'd really appreciate it, thanks!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 02 Sep 2013 01:22:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/labeling-with-python/m-p/133858#M10458</guid>
      <dc:creator>HitomiMaezawa1</dc:creator>
      <dc:date>2013-09-02T01:22:14Z</dc:date>
    </item>
    <item>
      <title>Re: Labeling with python</title>
      <link>https://community.esri.com/t5/python-questions/labeling-with-python/m-p/133859#M10459</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have just tried your code in ArcMap in the python window and it worked fine with no errors. Are you still having problems with this or have you managed to get it work now?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Cheers&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Dave&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 02 Sep 2013 16:15:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/labeling-with-python/m-p/133859#M10459</guid>
      <dc:creator>DaveBarrett</dc:creator>
      <dc:date>2013-09-02T16:15:33Z</dc:date>
    </item>
    <item>
      <title>Re: Labeling with python</title>
      <link>https://community.esri.com/t5/python-questions/labeling-with-python/m-p/133860#M10460</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Dave,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;yeah it still does not work.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I should try with different approach..&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for trying!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Sep 2013 04:30:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/labeling-with-python/m-p/133860#M10460</guid>
      <dc:creator>HitomiMaezawa1</dc:creator>
      <dc:date>2013-09-05T04:30:46Z</dc:date>
    </item>
    <item>
      <title>Re: Labeling with python</title>
      <link>https://community.esri.com/t5/python-questions/labeling-with-python/m-p/133861#M10461</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;There is a difference between SUPORTING label classes and&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;actually HAVING label classes.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;If you are hitting a layer that supports, but does not have, label classes&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;then layer.labelClasses will not return any label classes, &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;let alone an itterable list of label classes.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You should test the result list of layer.labelClasses before attempting to use a member of the list.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;As well, you have lblclass.expression = "[type]" unindented,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;so even if the layer is skipped (for not supporting label classes)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;you attempt to use the variable lblclass that is set inside the if statement,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;regardless of if the if has failed (and not set the variable) or not.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Sep 2013 16:34:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/labeling-with-python/m-p/133861#M10461</guid>
      <dc:creator>markdenil</dc:creator>
      <dc:date>2013-09-05T16:34:22Z</dc:date>
    </item>
  </channel>
</rss>

