<?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: get CIM layer object type in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/get-cim-layer-object-type/m-p/453487#M35590</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This did the trick. Thank you. It is still odd to me that 'type' is an available property if I look at the lyrx (ie json) file in a text editor but is not exposed in the CIM model. Oh well.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is what finally worked such that it prints the thematic field only if the appropriate renderer type is being used (your suggestion with slight modification):&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;aprx = arcpy.mp.ArcGISProject("CURRENT")&lt;BR /&gt;for map in aprx.listMaps():&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;for layer in map.listLayers():&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cim_lyr = layer.getDefinition('V2')&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;STRONG&gt;&amp;nbsp;if hasattr(cim_lyr.renderer, 'fields'):&lt;/STRONG&gt;&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;print("--- ---Thematic Field: " + str(cim_lyr.renderer.fields[0]))&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 02 Sep 2020 18:12:33 GMT</pubDate>
    <dc:creator>danashney</dc:creator>
    <dc:date>2020-09-02T18:12:33Z</dc:date>
    <item>
      <title>get CIM layer object type</title>
      <link>https://community.esri.com/t5/python-questions/get-cim-layer-object-type/m-p/453485#M35588</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am working with CIM layer definitions a bit. For a layer, I am wanting to get the field that the symbol thematic is based on (layerDefinitions.renderer.fields). However, some renderer types have the fields property while some don't.&amp;nbsp;CIMUniqueValueRenderer has the fields property while&amp;nbsp;CIMSimpleRenderer does not. If I try to access fields on a feature class that uses&amp;nbsp;&lt;SPAN&gt;CIMSimpleRenderer&amp;nbsp;I get an error. However, I cannot access the type property that I can plainly see in the json through the python therefore I cannot create logic around renderer type.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;aprx = arcpy.mp.ArcGISProject("CURRENT")&lt;BR /&gt;for map in aprx.listMaps():&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;for layer in map.listLayers():&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cim_lyr = layer.getDefinition('V2')&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if cim_lyr.renderer.fields is not None:&amp;nbsp; # this is obviously not working&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;#if cim_lyr.renderer.type == blah:&amp;nbsp; # this is what I would think I should be able to do&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;print("--- ---Thematic Field: " + str(cim_lyr.renderer.fields[0]))&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Error if I plug in a feature class with the wrong type:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;AttributeError: 'CIMSimpleRenderer' object has no attribute 'fields'&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;So, the object obviously knows its type per the error and per the json entry but does not offer me any good way of accessing its type through the CIM object model that I have found. How would I go about this?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 01 Sep 2020 19:38:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/get-cim-layer-object-type/m-p/453485#M35588</guid>
      <dc:creator>danashney</dc:creator>
      <dc:date>2020-09-01T19:38:54Z</dc:date>
    </item>
    <item>
      <title>Re: get CIM layer object type</title>
      <link>https://community.esri.com/t5/python-questions/get-cim-layer-object-type/m-p/453486#M35589</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;if you do a 'dir' on&amp;nbsp;&lt;SPAN style="background-color: #ffffff;"&gt;cim_lyr what attributes does it show for one with a table and one without.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffff;"&gt;I am thinking along the lines of&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; hasattr&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;cim_lyr&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'fields'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
    do something
&lt;SPAN class="keyword token"&gt;else&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
    something &lt;SPAN class="keyword token"&gt;else&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 20:13:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/get-cim-layer-object-type/m-p/453486#M35589</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2021-12-11T20:13:33Z</dc:date>
    </item>
    <item>
      <title>Re: get CIM layer object type</title>
      <link>https://community.esri.com/t5/python-questions/get-cim-layer-object-type/m-p/453487#M35590</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This did the trick. Thank you. It is still odd to me that 'type' is an available property if I look at the lyrx (ie json) file in a text editor but is not exposed in the CIM model. Oh well.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is what finally worked such that it prints the thematic field only if the appropriate renderer type is being used (your suggestion with slight modification):&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;aprx = arcpy.mp.ArcGISProject("CURRENT")&lt;BR /&gt;for map in aprx.listMaps():&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;for layer in map.listLayers():&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cim_lyr = layer.getDefinition('V2')&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;STRONG&gt;&amp;nbsp;if hasattr(cim_lyr.renderer, 'fields'):&lt;/STRONG&gt;&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;print("--- ---Thematic Field: " + str(cim_lyr.renderer.fields[0]))&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 02 Sep 2020 18:12:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/get-cim-layer-object-type/m-p/453487#M35590</guid>
      <dc:creator>danashney</dc:creator>
      <dc:date>2020-09-02T18:12:33Z</dc:date>
    </item>
    <item>
      <title>Re: get CIM layer object type</title>
      <link>https://community.esri.com/t5/python-questions/get-cim-layer-object-type/m-p/1143498#M63736</link>
      <description>&lt;P&gt;Use the built-in type() function.&amp;nbsp; I presume because type() is a built-in function you can't use it to access CIM properties, to avoid confusion.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;E.g. to do something with only point, line or polygon geometry:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;for lyr in map.listLayers():&lt;BR /&gt;&amp;nbsp; lyrCIM = lyr.getDefinition('V2')&lt;BR /&gt;&amp;nbsp; if type(lyrCIM) is arcpy.cim.CIMVectorLayers.CIMFeatureLayer:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; geomType = type(lyrCIM.renderer.symbol.symbol)&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; if geomType is arcpy.cim.CIMSymbols.CIMPointSymbol:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; doSomething()&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; elif geomType is arcpy.cim.CIMSymbols.CIMLineSymbol:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; doSomethingElse()&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; elif geomType is arcpy.cim.CIMSymbols.CIMPolygonSymbol:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; doAnotherThing()&lt;/P&gt;</description>
      <pubDate>Mon, 14 Feb 2022 00:41:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/get-cim-layer-object-type/m-p/1143498#M63736</guid>
      <dc:creator>andrew_k_barker</dc:creator>
      <dc:date>2022-02-14T00:41:03Z</dc:date>
    </item>
    <item>
      <title>Re: get CIM layer object type</title>
      <link>https://community.esri.com/t5/python-questions/get-cim-layer-object-type/m-p/1294123#M67741</link>
      <description>&lt;P&gt;This was just the question I had and the answer worked for me. Problem solved in 5 min. Kudos to Esri Community!&lt;/P&gt;</description>
      <pubDate>Tue, 30 May 2023 16:27:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/get-cim-layer-object-type/m-p/1294123#M67741</guid>
      <dc:creator>AlderMaps</dc:creator>
      <dc:date>2023-05-30T16:27:05Z</dc:date>
    </item>
    <item>
      <title>Re: get CIM layer object type</title>
      <link>https://community.esri.com/t5/python-questions/get-cim-layer-object-type/m-p/1294159#M67743</link>
      <description>&lt;P&gt;I tried this to begin with but it returns a class rather than just a string for easy comparison; I had to do just a tiny bit more work to get this method to work as well, e.g.:&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;aprx = arcpy.mp.ArcGISProject("CURRENT")
my_map = aprx.listMaps("CA Landslide Data")[0]

for lyr in my_map.listLayers():
    ciml = lyr.getDefinition("V3")
    if type(ciml).__name__ == "CIMTiledServiceLayer":
        #Do stuff      &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 May 2023 17:48:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/get-cim-layer-object-type/m-p/1294159#M67743</guid>
      <dc:creator>AlderMaps</dc:creator>
      <dc:date>2023-05-30T17:48:48Z</dc:date>
    </item>
  </channel>
</rss>

