My automation of building popups from Python code has been working ok. I can configure the title, the fields to be included (and order of those fields) and whether to show attachments or not.
I now want to include a link to an external web page. Doing this manually in a popup 'Text' item works fine. So I thought I should also be able to do this in my Python code. The relevant code is below
If I comment out the code for the Fields table item (CIMTableMediaInfo object), then the text item (the link) shows up in the popup and works. If I comment out the code for the Text item (CIMTextMedioInfo object), then the Fields table shows up in the popup nicely. This implies that I'm using correct Python code for each item because they work just fine that way.
However, if I attempt to have BOTH items included, the popup shows up blank. Looking at the popup configuration in ArcGIS Pro reveals that it has neither a Text item, nor a Fields table item. Instead, it shows only a Carousel item (with default settings). I never asked for a Carousel item!?!?
The relevant Python code is below.
What am I doing wrong here? How can I fix this code to work for both a Text item AND a Fields table item?
media_infos = []
cim = lyr.getDefinition('V3')
cim.popupInfo = arcpy.cim.CIMPopupInfo()
if configure_title:
cim.popupInfo.title = os.path.basename(lyr_name) + ": {name}"
if 'asset_id' in popup_fields:
link_text_info = arcpy.cim.CIMTextMediaInfo()
link_text_info.text = asset_link
media_infos.append(link_text_info)
if configure_fields_list:
table_media = arcpy.cim.CIMTableMediaInfo()
table_media.fields = popup_fields
media_infos.append(table_media)
cim.popupInfo.mediaInfos = media_infos
lyr.setDefinition(cim)
I've resolved this by adding the code below before (and including) the last two lines:
for i, info in enumerate(media_infos):
info.row = i
cim.popupInfo.mediaInfos = media_infos
lyr.setDefinition(cim)Ie, it appears that each CIMMediaInfo object needs to have a row number configured. Or at least in some circumstances (as this wasn't required when I had just Fields table and attachments items).
The documentation is either terrible, or I'm just hopeless at trying to find/understand the documentation. Either way, I just tried this as an experiment and was pleasantly surprised to find that it worked.