0

I am using ArcPy to extract popup information from project layers using ArcPy. The script I use fetches the popup configuration of the .aprx layer, extracts the popup information, and then saves the data into a CSV.

The function below checks if the popup configuration has been enabled. The Popups have been configured to display in the ArcGIS Pro. I noticed while debugging that it seems that there may not be a popup property present in the layer object.

# Fetches popup configuration from layer
def extract_popup_info_from_layer(layer):
 print(layer)
 popup_info = []
 print(layer.popupInfo)
 # Check if layer has a popup configuration
 try:
 if layer.supports("POPUP"):
 popup_properties = layer.popupInfo
 print(layer.popupInfo)
 if popup_properties:
 # Loops through each field in the popup
 for field in popup_properties.fieldInfos:
 popup_info.append({
 "Field Name": field.fieldName,
 "Label": field.label,
 "Visible": field.visible,
 "Format": field.format
 })
 else:
 print(f"No popup configuration found for layer: {layer.name}")
 else:
 print(f"Layer '{layer.name}' does not support popups")
 except Exception as e:
 print(f"Error fetching popup info from layer: '{layer.name}': {e} ")
 return popup_info

I cannot find a way to access this feature with ArcPy. Any ideas on how to resolve this issue?

Vince
20.5k16 gold badges49 silver badges65 bronze badges
asked Dec 31, 2024 at 18:23

1 Answer 1

2

The sample code reads like pseudo code and not actual ArcPy code because it describes logical steps one would take, but it gets the actual syntax wrong in many places. API reference documentation from a vendor is always the best place to start before jumping into code generation.

As an aside, when first writing new code blocks and debugging, don't use try/except blocks until the code is nearly complete because they hide all the useful error information that can help troubleshoot, especially when doing except Exception as e:.

As Layer - ArcGIS Pro | Documentation states, the supports() method does not support a "POPUP" argument, so the rest of the code is moot after that point. Although layers don't have a pop-up property or method to directly access it, pop-up information is accessible through Esri's Cartographic Information Model (GitHub - Esri/cim-spec), and layers have a getDefinition method to retrieve the CIM definition for the layer.

Looking over CIMPopup documentation specifically, one can see that retrieving pop-up information is much more complicated than the pseudo code indicates. Pop-ups can be very complex having multiple types of items (text, fields, images, charts, etc...) displayed at the same time. If one knows ahead of time how the pop-ups will be setup, writing actual code can be simplified, but writing ArcPy code that can handle all types of possible items in a pop-up is way more than what someone should be asking for on a forum.

answered Dec 31, 2024 at 21:49

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.