<?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 How to access Layer properties from a GPFeatureLayer / MappingLayerObject? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/how-to-access-layer-properties-from-a/m-p/1191018#M64974</link>
    <description>&lt;P&gt;When writing a python script tool, I often have GPFeatureLayer as the parameter type.&amp;nbsp; These are great because then Parameter.value gives you access to most of the properties and methods of a layer as accessed through arcpy.Map.listLayers(), but infuriating because you can't access some properties.&amp;nbsp; The difference is that Parameter.value is a MappingLayerObject, whatever that means, and arcpy.Map.listLayers() returns a list of arcpy.Layer objects.&lt;/P&gt;&lt;P&gt;So, let's say I have a python script toolbox set up something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def getParameterInfo(self):
    param0 = arcpy.Parameter(
        name='layers',
        displayName='Layers',
        direction='Input',
        datatype='GPFeatureLayer',
        parameterType='Required',
        enabled=True
    )
    return [param0]


def execute(self, parameters, messages):
    gp_layer = parameters[0].value
    layer_name = gp_layer.name
    
    aprx = arcpy.mp.ArcGISProject('current')
    active_map = aprx.activeMap
    arcpy_layer = get_arcpy_layer()  # ????????
    sd_draft = active_map.getWebLayerSharingDraft(
        'HOSTING_SERVER', 'FEATURE', layer_name, [arcpy_layer]
    )&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Now the context I was interested in was writing a tool to publish a bunch of layers as web layers, one by one.&amp;nbsp; So that means I had to use the method arcpy.Map.getWebLayerSharingDraft(), which as one of its parameters requires an arcpy.Layer object (trying to use gp_layer will throw an error).&amp;nbsp; But how do I get the right one?&amp;nbsp; It's possible to give two layers the same name, so arcpy.Map.listLayers() is useless to me.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;In ArcGIS Pro, in the map properties &amp;gt; general tab, there's a checkbox called "Allow assignment of unique numeric IDs for sharing web layers" and it seems like it's there to solve this exact problem.&amp;nbsp; When you check that box, go into a layer's properties &amp;gt; general &amp;gt; LayerID, and you'll see indeed the layers have unique IDs.&lt;/P&gt;&lt;P&gt;How do we access those unique IDs, and thereby link every MappingLayerObject to the correct Layer?&amp;nbsp; For a Layer object, you hop inside the CIM and read the property called serviceLayerID:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;aprx = arcpy.mp.ArcGISProject('current')
m = aprx.activeMap
for layer in m.listLayers():
    cim = layer.getDefinition('V3')
    layer_id = cim.serviceLayerID&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;If you run dir() on a MappingLayerObject, you'll see it shares many properties and methods with a Layer object, but getDefinition() is among the missing.&amp;nbsp; Instead, there is a method called &lt;/SPAN&gt;&lt;SPAN&gt;GetCimJSONString(), which gives you basically the same thing as getDefinition(), but as a string.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;So finally, I would write a function like the following, and call it on line 19 of my first snippet.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import json
def get_arcpy_layer(gp_feature_layer, pro_map):
    gp_cim = json.loads(gp_feature_layer.GetCimJSONString())
    gp_layer_id = gp_cim['serviceLayerID']

    for layer in pro_map.listLayers():
        cim = layer.getDefinition('V3')
        layer_id = cim.serviceLayerID
        if layer_id == gp_layer_id:
            return layer&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks for reading, I hope this is helpful to somebody someday.&amp;nbsp; I have struggled with this concept in many more contexts beyond just publishing web layers.&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 08 Jul 2022 22:22:54 GMT</pubDate>
    <dc:creator>SamSzotkowski</dc:creator>
    <dc:date>2022-07-08T22:22:54Z</dc:date>
    <item>
      <title>How to access Layer properties from a GPFeatureLayer / MappingLayerObject?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-access-layer-properties-from-a/m-p/1191018#M64974</link>
      <description>&lt;P&gt;When writing a python script tool, I often have GPFeatureLayer as the parameter type.&amp;nbsp; These are great because then Parameter.value gives you access to most of the properties and methods of a layer as accessed through arcpy.Map.listLayers(), but infuriating because you can't access some properties.&amp;nbsp; The difference is that Parameter.value is a MappingLayerObject, whatever that means, and arcpy.Map.listLayers() returns a list of arcpy.Layer objects.&lt;/P&gt;&lt;P&gt;So, let's say I have a python script toolbox set up something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def getParameterInfo(self):
    param0 = arcpy.Parameter(
        name='layers',
        displayName='Layers',
        direction='Input',
        datatype='GPFeatureLayer',
        parameterType='Required',
        enabled=True
    )
    return [param0]


def execute(self, parameters, messages):
    gp_layer = parameters[0].value
    layer_name = gp_layer.name
    
    aprx = arcpy.mp.ArcGISProject('current')
    active_map = aprx.activeMap
    arcpy_layer = get_arcpy_layer()  # ????????
    sd_draft = active_map.getWebLayerSharingDraft(
        'HOSTING_SERVER', 'FEATURE', layer_name, [arcpy_layer]
    )&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Now the context I was interested in was writing a tool to publish a bunch of layers as web layers, one by one.&amp;nbsp; So that means I had to use the method arcpy.Map.getWebLayerSharingDraft(), which as one of its parameters requires an arcpy.Layer object (trying to use gp_layer will throw an error).&amp;nbsp; But how do I get the right one?&amp;nbsp; It's possible to give two layers the same name, so arcpy.Map.listLayers() is useless to me.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;In ArcGIS Pro, in the map properties &amp;gt; general tab, there's a checkbox called "Allow assignment of unique numeric IDs for sharing web layers" and it seems like it's there to solve this exact problem.&amp;nbsp; When you check that box, go into a layer's properties &amp;gt; general &amp;gt; LayerID, and you'll see indeed the layers have unique IDs.&lt;/P&gt;&lt;P&gt;How do we access those unique IDs, and thereby link every MappingLayerObject to the correct Layer?&amp;nbsp; For a Layer object, you hop inside the CIM and read the property called serviceLayerID:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;aprx = arcpy.mp.ArcGISProject('current')
m = aprx.activeMap
for layer in m.listLayers():
    cim = layer.getDefinition('V3')
    layer_id = cim.serviceLayerID&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;If you run dir() on a MappingLayerObject, you'll see it shares many properties and methods with a Layer object, but getDefinition() is among the missing.&amp;nbsp; Instead, there is a method called &lt;/SPAN&gt;&lt;SPAN&gt;GetCimJSONString(), which gives you basically the same thing as getDefinition(), but as a string.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;So finally, I would write a function like the following, and call it on line 19 of my first snippet.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import json
def get_arcpy_layer(gp_feature_layer, pro_map):
    gp_cim = json.loads(gp_feature_layer.GetCimJSONString())
    gp_layer_id = gp_cim['serviceLayerID']

    for layer in pro_map.listLayers():
        cim = layer.getDefinition('V3')
        layer_id = cim.serviceLayerID
        if layer_id == gp_layer_id:
            return layer&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks for reading, I hope this is helpful to somebody someday.&amp;nbsp; I have struggled with this concept in many more contexts beyond just publishing web layers.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jul 2022 22:22:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-access-layer-properties-from-a/m-p/1191018#M64974</guid>
      <dc:creator>SamSzotkowski</dc:creator>
      <dc:date>2022-07-08T22:22:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to access Layer properties from a GPFeatureLayer / MappingLayerObject?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-access-layer-properties-from-a/m-p/1652728#M74729</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Hi there,&lt;BR /&gt;&lt;BR /&gt;my answer might be a little late, but I struggled with the same issue for a long time, until I discovered the URI-property of the Layerclass. It can be accessed via the&amp;nbsp;MappingLayerObject you obtain from parameter.value as well as the Layerobject you obtain through&amp;nbsp;arcpy.Map.listLayers().&lt;BR /&gt;You can then check for a match in the URI-property of both objects which, like your code above, solves the problem with dublicates in TOC layernames.&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;parameterlayer = parameters[0].value # returns a MappingLayerObject
p = arcpy.mp.ArcGISProject("CURRENT")
m = p.activeMap
layers_toc = m.listLayers()
for layer in layers_toc:  # returns list of Layerobjects
    if layer.URI == parameterlayer.URI:
        # do something&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 24 Sep 2025 07:46:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-access-layer-properties-from-a/m-p/1652728#M74729</guid>
      <dc:creator>Chris_Ste</dc:creator>
      <dc:date>2025-09-24T07:46:11Z</dc:date>
    </item>
  </channel>
</rss>

