# Name: PopulateMapSheetInfo_sample.py
# Description: Replaces tagged text in the layout with attributes from the AOI feature
# Import System Modules
import arcpy
# Check Out Extensions
arcpy.CheckOutExtension('Foundation')
# Setting the environment
arcpy.env.overwriteOutput = True
# Setting Local Variables
in_layout = r'C:\Data\PopMapSheetInfo_Layout.pagx'
area_of_interest = r'C:\Data\MapIndex.gdb\MapIndex\TLM50_Index'
lookup_table = r'C:\Data\MapIndex.gdb\PopMapInfo'
# Making a feature layer from the Area of Interest features, and selecting a single feature based on the NRN field
arcpy.management.MakeFeatureLayer(area_of_interest, 'AOI_Index')
arcpy.management.SelectLayerByAttribute('AOI_Index', 'NEW_SELECTION', "NRN = 'V795X16574'")
# Calling the Populate Map Sheet info tool to add values to the dynamic text elements in the layout
arcpy.topographic.PopulateMapSheetInfo(in_layout, 'AOI_Index', lookup_table)
# Getting all messages, warnings, and errors from the tool run and printing the results back to the user
messages = arcpy.GetMessages(0)
warnings = arcpy.GetMessages(1)
errors = arcpy.GetMessages(2)
arcpy.AddMessage('Tool Messages: {}\nTool Warnings: {}\nTool Errors{}\n'.format(messages, warnings, errors))
# Check In Extensions
arcpy.CheckInExtension('Foundation')