Hi,
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.
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.
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)
Solved! Go to Solution.
Hi @Billy,
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.
Make sure to save your APRX using the script, add the following at the end of your function.
aprx.save()
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.
Hi @Billy,
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.
Make sure to save your APRX using the script, add the following at the end of your function.
aprx.save()
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.