<?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: How to Modify Popup Fields in ArcGIS Pro with Arcpy in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/how-to-modify-popup-fields-in-arcgis-pro-with/m-p/1583096#M73713</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/43830"&gt;@Billy&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;You are using ArcGIS Pro 3.4.2 so the version for the getDefinition should be "V3" not "V2" which is for the Pro 2.X.X series.&lt;/P&gt;&lt;P&gt;Make sure to save your APRX using the script, add the following at the end of your function.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;aprx.save()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Run the Notebook in a Project that is not the one you want to update and see if it works when you re-open the Project of interest.&lt;/P&gt;</description>
    <pubDate>Fri, 07 Feb 2025 14:22:09 GMT</pubDate>
    <dc:creator>Clubdebambos</dc:creator>
    <dc:date>2025-02-07T14:22:09Z</dc:date>
    <item>
      <title>How to Modify Popup Fields in ArcGIS Pro with Arcpy</title>
      <link>https://community.esri.com/t5/python-questions/how-to-modify-popup-fields-in-arcgis-pro-with/m-p/1583052#M73712</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to use arcpy to modify the popup configuration for a map in ArcGIS Pro 3.4.2. The dataset is a Utility Network and the map is configured with subtype layers. My code runs without error, but the popup is not changed on the map, it continues to show all the fields instead of just the 4 fields that I want to show.&lt;/P&gt;&lt;P&gt;This is the code that I'm using. I included 2 version of the "configure_popup_fields" function. Both functions return no error, but the popup is not updated. I am running the code using notebook inside the project.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy

def configure_popup_fields(project_path, map_name, layer_name, desired_fields):
    """
    Configure popup fields for a feature service layer using correct CIMPopup classes
    
    Parameters:
    project_path (str): Full path to the .aprx project file, or 'current' for current project
    map_name (str): Name of the map
    layer_name (str): Name of the layer
    desired_fields (list): List of field names to show in popup
    """
    try:
        # Open the project
        aprx = arcpy.mp.ArcGISProject(project_path)
        
        # Get the map and layer
        target_map = next((m for m in aprx.listMaps() if m.name == map_name), None)
        target_layer = next((l for l in target_map.listLayers() if l.name == layer_name), None)
        
        if not target_layer:
            print("Layer not found")
            return
            
        # Get the CIM definition
        layer_cim = target_layer.getDefinition('V2')
        
        # Create the table media info and set the fields
        media = arcpy.cim.CIMPopup.CIMTableMediaInfo()
        media.fields = desired_fields
        
        # Create popup info and set the media info
        popup = arcpy.cim.CIMPopup.CIMPopupInfo()
        popup.mediaInfos = [media]
        
        # Set the popup info on the layer
        layer_cim.popupInfo = popup
        
        # Apply the changes
        target_layer.setDefinition(layer_cim)
        print("Popup configuration updated successfully")
        
    except Exception as e:
        print(f"Error configuring popup: {str(e)}")


def configure_popup_fields(project_path, map_name, layer_name, desired_fields):
    """
    Configure popup fields for a feature service layer using CIM specification
    
    Parameters:
    project_path (str): Full path to the .aprx project file, or 'current' for current project
    map_name (str): Name of the map
    layer_name (str): Name of the layer
    desired_fields (list): List of field names to show in popup
    """
    try:
        # Open the project
        aprx = arcpy.mp.ArcGISProject(project_path)
        
        # Get the map and layer
        target_map = next((m for m in aprx.listMaps() if m.name == map_name), None)
        target_layer = next((l for l in target_map.listLayers() if l.name == layer_name), None)
        
        if not target_layer:
            print("Layer not found")
            return
            
        # Get the CIM definition
        layer_cim = target_layer.getDefinition('V2')
        
        # Create popup info if it doesn't exist
        popup = arcpy.cim.CIMPopup.CIMPopupInfo()
        
        # Create table media info with specified fields
        table_media = arcpy.cim.CIMPopup.CIMTableMediaInfo()
        table_media.fields = desired_fields
        
        # Set up the popup configuration
        popup.mediaInfos = [table_media]
        popup.useQuotes = False
        popup.separator = ", "
        
        # Set the popup info on the layer
        layer_cim.popupInfo = popup
        
        # Apply the changes
        target_layer.setDefinition(layer_cim)
        print("Popup configuration updated successfully")
        
    except Exception as e:
        print(f"Error configuring popup: {str(e)}")


if __name__ == "__main__":
    project_path = r"Path_to_Prject\Operation_Map.aprx"
    map_name = "System Design Map _ Python"
    layer_name = "Medium Voltage Fuse"
    
    #Fields you might want to show in the popup
    desired_fields = [
        "assetid",
        "model",
        "manufacturer",
        "installdate"        
    ]
    
    configure_popup_fields(project_path, map_name, layer_name, desired_fields)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Feb 2025 12:56:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-modify-popup-fields-in-arcgis-pro-with/m-p/1583052#M73712</guid>
      <dc:creator>Billy</dc:creator>
      <dc:date>2025-02-07T12:56:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to Modify Popup Fields in ArcGIS Pro with Arcpy</title>
      <link>https://community.esri.com/t5/python-questions/how-to-modify-popup-fields-in-arcgis-pro-with/m-p/1583096#M73713</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/43830"&gt;@Billy&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;You are using ArcGIS Pro 3.4.2 so the version for the getDefinition should be "V3" not "V2" which is for the Pro 2.X.X series.&lt;/P&gt;&lt;P&gt;Make sure to save your APRX using the script, add the following at the end of your function.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;aprx.save()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Run the Notebook in a Project that is not the one you want to update and see if it works when you re-open the Project of interest.&lt;/P&gt;</description>
      <pubDate>Fri, 07 Feb 2025 14:22:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-modify-popup-fields-in-arcgis-pro-with/m-p/1583096#M73713</guid>
      <dc:creator>Clubdebambos</dc:creator>
      <dc:date>2025-02-07T14:22:09Z</dc:date>
    </item>
  </channel>
</rss>

