I am trying to fix a broken map in map templates that is generated through Land Resource Manager (LRM) where we manage all our data. When we generate maps we select the features we want to map, and group them by an attribute. Tags for the maps can be referenced populated in the map manager settings with Select statements on tables and views in the sde which LRM is connected to.
Some of the tags(dynamic text elements) in the map layout rely directly on layer attributes but others are pulled from views that we have in our enterprise geodatabase. The views I am trying to access are not populating my tags properly.
When basing my tags off the primary_key_value, the tags would only show one of two primary_key_value's that exist with the parameters for the tag. My python script grabs all of the selected primary_key_values, but seems to not be able to display past one value.
What I'm finding is all the tags that also use a group_value/parent_primary_key_value, display properly. (Although these tags I believe are also pulling directly from layer attributes)
I have ruled out map formatting as I have also just selected the actual primary key values and those show up.
I have looked out how my getParameterAsText is formatted and this hasn't helped me
I have tried to get my python script to access the views directly and create the tags within the script, but I don't think my script is properly accessing the sde. This has been a whole different problem
Maybe someone has some insight for me. I am very green with Python and SQL.
Here is a sample tag that doesn't work for [RSP_TSFA] - I have checked for null values (it doesn't pull attributes from the 'TSFA - RSP- Active' layer.
SELECT ROAD_ROAD_NAME || ' ' || RASS_START_METRE_NBR || ' ' || RASS_END_METRE_NBR || ' ' || RASS_ACTIVITY_MEMO AS RASS_ACTIVITY_MEMO
FROM FOREST.V_MAP_RSP_TSFA_NEW
WHERE ROAD_SEQ_NBR = ([PRIMARY_KEY_VALUE])
#Here is my original script
import arcpy
import Tkinter
import tkMessageBox
import sys
import os
import time
import string
arcpy.env.overwriteOutput = True
dbconnection = 'F:\\LRM\\Templates\\DatabaseConnections\\IFPFOP4_AS_FORESTVIEW.sde'
arcpy.env.workspace = dbconnection
mxd = arcpy.mapping.MapDocument("CURRENT")
above sets the mxd to be the current mxd
# gathers the Parent Primary Key Value variable that is fed to template from Map Manager to the current map
GroupBy_Key = arcpy.GetParameterAsText(0).split(",")[15]
GroupBy_Key_value = GroupBy_Key.split("=")[1]
#tkMessageBox.showinfo("text",GroupBy_Key_value)
Primary_Key = arcpy.GetParameterAsText(0).split(",")[1]
Primary_Key_value = Primary_Key.split("=")[1]
Primary_Key_value = format(Primary_Key_value).replace('|',',')
#tkMessageBox.showinfo("text",Primary_Key_value)
#rdpm = [i for i in arcpy.da.SearchCursor(arcpy.mapping.layer('Road Construction Standard'), 'RDPM_SEQ_NBR', 'ROAD_SEQ_NBR in (' + Primary_Key_value + ')')]
rspOutputs = r'F:\LRM\Templates\Python\RSP_Outputs.txt'
with open(rspOutputs, 'w') as txt:
txt.write(Primary_Key_value + '\n')
txt.write(GroupBy_Key_value + '\n')
#txt.write(allText)
#txt.write(rdpm)
# performs a definition query on each layer below based on the Parent_Primary_Key_value fed from Map Manager variable sring above
for lyr in arcpy.mapping.ListLayers(mxd):
if lyr.name == "Additional Stabilization":
lyr.definitionQuery = 'ROAD_SEQ_NBR in (' + Primary_Key_value + ') AND PVER_VERSION_NBR = ' + GroupBy_Key_value
if lyr.name == "Additional Stabilization POC":
lyr.definitionQuery = 'ROAD_SEQ_NBR in (' + Primary_Key_value + ') AND PVER_VERSION_NBR = ' + GroupBy_Key_value
if lyr.name == "Road Hub":
lyr.definitionQuery = 'ROAD_SEQ_NBR in (' + Primary_Key_value + ')'
if lyr.name == "Appraisal Structures ECE Labels":
lyr.definitionQuery = 'ROAD_SEQ_NBR in (' + Primary_Key_value + ') AND PVER_VERSION_NBR = ' + GroupBy_Key_value
if lyr.name == "Road Section - Labels":
lyr.definitionQuery = 'ROAD_SEQ_NBR in (' + Primary_Key_value + ') AND CP_VERSION = ' + GroupBy_Key_value
if lyr.name == "TSFA - RSP - ACTIVE":
lyr.definitionQuery = 'ROAD_SEQ_NBR in (' + Primary_Key_value + ') AND RASS_STATUS in (' ''' 'D' ''' ')'
if lyr.name == "Road Construction Standard":
lyr.definitionQuery = 'ROAD_SEQ_NBR in (' + Primary_Key_value + ') AND CP_VERSION = ' + GroupBy_Key_value
if lyr.name == "Road_Callout_Editable":
lyr.definitionQuery = 'ROAD_SEQ_NBR in (' + Primary_Key_value + ')'
if lyr.name == "Slope Arrows":
lyr.definitionQuery = 'ROAD_SEQ_NBR in (' + Primary_Key_value + ')'
# perform a layout refresh
arcpy.RefreshActiveView()
# The following removes the MXD from memory
del mxd