<?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: Maintaining LayerID in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/maintaining-layerid/m-p/1570158#M91424</link>
    <description>&lt;LI-CODE lang="python"&gt;def hide_empty_fields(data_source):
    # Create a FieldInfo object
    field_info = arcpy.Describe(data_source).fieldInfo

    # Get a list of all fields in the data source
    fields = [field.name for field in arcpy.ListFields(data_source)]

    # Loop through the fields and check if they are empty across all rows
    with arcpy.da.SearchCursor(data_source, fields) as cursor:
        for field in fields:
            is_empty = True
            for row in cursor:
                if row[fields.index(field)] not in [None, '', ' ']:
                    is_empty = False
                    break
            if is_empty:
                # Set the field visibility to "HIDDEN"
                for i in range(field_info.count):
                    if field_info.getFieldName(i) == field:
                        field_info.setVisible(i, "HIDDEN")
            cursor.reset()  # Reset cursor to the beginning for the next field check

    # Apply the updated field info to the existing layer or table
    if isinstance(data_source, arcpy._mp.Layer):
        arcpy.management.MakeFeatureLayer(data_source, data_source.name, field_info=field_info)
    else:
        arcpy.management.MakeTableView(data_source, data_source.name, field_info=field_info)&lt;/LI-CODE&gt;</description>
    <pubDate>Thu, 19 Dec 2024 14:05:02 GMT</pubDate>
    <dc:creator>SeanPark</dc:creator>
    <dc:date>2024-12-19T14:05:02Z</dc:date>
    <item>
      <title>Maintaining LayerID</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/maintaining-layerid/m-p/1569894#M91404</link>
      <description>&lt;P&gt;I'm currently using a ArcGIS Pro and built in Jupyter Notebook to make changes to my feature layers (and some feature tables). Basically I'm hiding all the empty fields using field_info.setVisible().&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then I make new feature layer by overwriting it with this code. arcpy.management.MakeFeatureLayer(data_source, data_source.name, field_info=field_info)&amp;nbsp;&lt;/P&gt;&lt;P&gt;Just for reference,&amp;nbsp;field_info = arcpy.Describe(data_source).fieldInfo&lt;/P&gt;&lt;P&gt;When I run through all the layers with code, it resets the Layer ID from 0 and on.&lt;/P&gt;&lt;P&gt;I use these layers for AGOL (Web map) updates and the assigned Layer ID property is very important.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can't seem to find any document regarding either maintaining the Layer ID or assigning Layer ID by code. All I found was the manual way of right clicking the layer &amp;gt;&amp;nbsp; properties &amp;gt; set Layer ID.&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is extremely inconvenient as I have 20+ layers in each map and over 30 maps to work on.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help would be greatly appreciated.&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 18 Dec 2024 20:29:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/maintaining-layerid/m-p/1569894#M91404</guid>
      <dc:creator>SeanPark</dc:creator>
      <dc:date>2024-12-18T20:29:34Z</dc:date>
    </item>
    <item>
      <title>Re: Maintaining LayerID</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/maintaining-layerid/m-p/1569971#M91411</link>
      <description>&lt;P&gt;I have not tried this by clobbering existing layers with the MakeFeatureLayer tool, but have used other tools/code to overwrite feature layers within my Pro project that I publish/overwrite existing services.&lt;/P&gt;&lt;P&gt;In my case, I check the Map layer properties to Allow assignment of unique numeric IDs for sharing web layers:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="RhettZufelt_0-1734555630366.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/122072iD73F7098504C7AB9/image-size/medium?v=v2&amp;amp;px=400" role="button" title="RhettZufelt_0-1734555630366.png" alt="RhettZufelt_0-1734555630366.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;And, in the Geoprocessing options, Allow geoprocessing tools to overwrite exiting datasets, and un-check "Remove layers that reference data overwritten by geoprocessing tools":&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="RhettZufelt_1-1734555687109.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/122073i1E543E867D33AB1F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="RhettZufelt_1-1734555687109.png" alt="RhettZufelt_1-1734555687109.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;This way, the layers are not removed, updated, then re-added, they are updated in place and the ID assignments do not change.&amp;nbsp; I can then overwrite my feature service with the new data while maintaining item ID's.&lt;/P&gt;&lt;P&gt;In case this helps in your scenario,&lt;/P&gt;&lt;P&gt;R_&lt;/P&gt;</description>
      <pubDate>Wed, 18 Dec 2024 21:03:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/maintaining-layerid/m-p/1569971#M91411</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2024-12-18T21:03:26Z</dc:date>
    </item>
    <item>
      <title>Re: Maintaining LayerID</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/maintaining-layerid/m-p/1569980#M91412</link>
      <description>&lt;P&gt;Thanks for your reply!&lt;/P&gt;&lt;P&gt;It seems like unless I specify MakeFeatureLayer, the layer on the map won't get updated.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Without it, something seems to be processing successfully, but no direct changes occur on the layer on the map.&lt;/P&gt;&lt;P&gt;To elaborate a little more, here's the snippet of hiding fields.&lt;/P&gt;&lt;P&gt;# Function to hide empty fields in a layer or table&lt;BR /&gt;def hide_empty_fields(data_source):&lt;BR /&gt;# Create a FieldInfo object&lt;BR /&gt;field_info = arcpy.Describe(data_source).fieldInfo&lt;/P&gt;&lt;P&gt;# Get a list of all fields in the data source&lt;BR /&gt;fields = [field.name for field in arcpy.ListFields(data_source)]&lt;/P&gt;&lt;P&gt;# Loop through the fields and check if they are empty across all rows&lt;BR /&gt;with arcpy.da.SearchCursor(data_source, fields) as cursor:&lt;BR /&gt;for field in fields:&lt;BR /&gt;is_empty = True&lt;BR /&gt;for row in cursor:&lt;BR /&gt;if row[fields.index(field)] not in [None, '', ' ']:&lt;BR /&gt;is_empty = False&lt;BR /&gt;break&lt;BR /&gt;if is_empty:&lt;BR /&gt;# Set the field visibility to "HIDDEN"&lt;BR /&gt;for i in range(field_info.count):&lt;BR /&gt;if field_info.getFieldName(i) == field:&lt;BR /&gt;field_info.setVisible(i, "HIDDEN")&lt;BR /&gt;cursor.reset() # Reset cursor to the beginning for the next field check&lt;/P&gt;&lt;P&gt;# Apply the updated field info to the existing layer or table&lt;BR /&gt;if isinstance(data_source, arcpy._mp.Layer):&lt;BR /&gt;arcpy.management.MakeFeatureLayer(data_source, data_source.name, field_info=field_info)&lt;BR /&gt;else:&lt;BR /&gt;arcpy.management.MakeTableView(data_source, data_source.name, field_info=field_info)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Unless I have those last two lines, the layers won't get updated, but that tool resets the Layer ID. (I've tried your recommendation)&lt;/P&gt;</description>
      <pubDate>Wed, 18 Dec 2024 21:36:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/maintaining-layerid/m-p/1569980#M91412</guid>
      <dc:creator>SeanPark</dc:creator>
      <dc:date>2024-12-18T21:36:40Z</dc:date>
    </item>
    <item>
      <title>Re: Maintaining LayerID</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/maintaining-layerid/m-p/1570014#M91414</link>
      <description>&lt;P&gt;Hard to follow your code as it has lost in indentation.&lt;/P&gt;&lt;P&gt;If you edit/post code following this post, it will maintain all the indentation, etc.&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.esri.com/t5/community-help-documents/how-to-insert-code-in-your-post/ta-p/914552" target="_self"&gt;Inserting Code in AGOL post.&lt;/A&gt;&lt;/P&gt;&lt;P&gt;R_&lt;/P&gt;</description>
      <pubDate>Wed, 18 Dec 2024 22:26:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/maintaining-layerid/m-p/1570014#M91414</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2024-12-18T22:26:55Z</dc:date>
    </item>
    <item>
      <title>Re: Maintaining LayerID</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/maintaining-layerid/m-p/1570158#M91424</link>
      <description>&lt;LI-CODE lang="python"&gt;def hide_empty_fields(data_source):
    # Create a FieldInfo object
    field_info = arcpy.Describe(data_source).fieldInfo

    # Get a list of all fields in the data source
    fields = [field.name for field in arcpy.ListFields(data_source)]

    # Loop through the fields and check if they are empty across all rows
    with arcpy.da.SearchCursor(data_source, fields) as cursor:
        for field in fields:
            is_empty = True
            for row in cursor:
                if row[fields.index(field)] not in [None, '', ' ']:
                    is_empty = False
                    break
            if is_empty:
                # Set the field visibility to "HIDDEN"
                for i in range(field_info.count):
                    if field_info.getFieldName(i) == field:
                        field_info.setVisible(i, "HIDDEN")
            cursor.reset()  # Reset cursor to the beginning for the next field check

    # Apply the updated field info to the existing layer or table
    if isinstance(data_source, arcpy._mp.Layer):
        arcpy.management.MakeFeatureLayer(data_source, data_source.name, field_info=field_info)
    else:
        arcpy.management.MakeTableView(data_source, data_source.name, field_info=field_info)&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 19 Dec 2024 14:05:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/maintaining-layerid/m-p/1570158#M91424</guid>
      <dc:creator>SeanPark</dc:creator>
      <dc:date>2024-12-19T14:05:02Z</dc:date>
    </item>
  </channel>
</rss>

