1. #==[ X X X X X X X X X X X X X X X X X X X ]===========================================================#
# _____
# _.-'' ``-._
# ,' `. CPL PEARCE CLINTON
# / XXX XXXXXXX XXX
# / XXXX XXXXXXX
# : : XXXXX
# |_______________________| V 1.3
# ;_______________________:
# / | ,' `. |
# : `.___.-' ___ `-.___.' :
# /`._ _,-' `-._ _,'/
# ,.-' _.-._ `-./.
# ,' _,' ___ `._ `.
# | :. ,'_,-' . `-._`-. .: |
# | ':. '-' | `-' .:' |
# : ':. | .:' ;
# ,- | -. /
# ' ' / `/
# ,` ,'^`. '. /
# ( O`-','-'.`-'O ) /
# `-.___,' `.___.-'
#
#
#==[ C H A N G E L O G ]===========================================================================#
#v.1.0 Release
#v.1.1 Cleaned up Zoom To Features
#v.1.2 Added Classification Colors
#v.1.3 Optimization; refresh on start, Created Geodatabse, removed online layers, removed US States from loc
view
#==[ I M P O R T A D D O N S ]=====================================================================#
import arcpy
from arcpy import env
import sys
import string
import os
import re
import time
#==[ M I S C D E T A I L S ]=======================================================================#
arcpy.env.workspace = "in_memory" #Write to in_memory
arcpy.env.overwriteOutput = True #Overwrite = True
arcpy.Delete_management("in_memory") #Kill in_memory
#==[ G E T M X D ]=================================================================================#
mxd = arcpy.mapping.MapDocument("CURRENT") #MXD reference
#==[ G E T D A T A F R A M E S ]===================================================================#
#Get df(s)
dfMain = arcpy.mapping.ListDataFrames(mxd, "dfMain")[0]
dfMainCurrentScale = dfMain.scale
dfLoc = arcpy.mapping.ListDataFrames(mxd, "dfLoc")[0]
#[X]Get Map Elements
strMapName = arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT","textMapName")[0]
strMapLoc = arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT","textMapLoc")[0]
strClassification = arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT","textClassification")[0]
#Get Script Parameters
new_strMapName = arcpy.GetParameter(0).upper() #Get Map Name
new_strMapLoc = arcpy.GetParameter(1).upper() #Get Map Location
new_strClassification = arcpy.GetParameter(2).upper() #Get Map Classification
boolStripClassification = arcpy.GetParameter(3) #Get Boolean Strip Class
str_ClassificationColor = arcpy.GetParameter(4) #Get Classification Color
# PARAM 4,5,6,7,8,9 FREE #Free Parameters
str_NearestCity = arcpy.GetParameter(10) #Get Map Nearest City
str_NearestCityProv = arcpy.GetParameter(11).upper() #Get Map MGRS Name
str_MgrsGrid = arcpy.GetParameter(12).upper() #Get Map MGRS Grid
str_MgrsGrid.replace(" ", "").replace(",","") #Strip spaces from str_MgrsGrid
str_MapScale = arcpy.GetParameter(13) #Get Map Scale
int_CustomScale = arcpy.GetParameter(14).upper() #Get Map Custom Scale
int_CustomScale.replace(" ", "").replace(",","") #Strip spaces from int_CustomScale
#==[ H I D E L A Y E R S ]=========================================================================#
2. for lyrOff in arcpy.mapping.ListLayers(mxd):
lyrOff.visible = False
#==[ R E F R E S H T H E M A P ]=================================================================#
#AFTER HIDE Refresh Page
arcpy.RefreshActiveView()
#==[ C H A N G E M A P D E T A I L S ]===========================================================#
#Change Map Name and Location
if new_strMapName == "NO CHANGE":
pass
arcpy.AddMessage("NO MAP NAME SPECIFIED")
else:
arcpy.AddMessage("###### MAP NAME SET TO " + new_strMapName + " ######")
#Set Map Name
strMapName.text = '<bol>' + new_strMapName + '</bol>'
#[X]Get New Map Location
#If no new loc
if new_strMapLoc == "NO CHANGE, NO CHANGE":
pass
arcpy.AddMessage("NO SUB TITLE SPECIFIED")
else:
arcpy.AddMessage("###### MAP LOCATION SET TO " + new_strMapLoc + " ######")
#Name Map Loc
strMapLoc.text = '<bol>' + new_strMapLoc + '</bol>'
#==[ M A P C L A S S I F I C A T I O N ]===========================================================#
#Get Current Map Classification
for elm in arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT","textClassification"):
mapClassText = elm.text
cleanClassText = re.sub("<.*?>", "", mapClassText)
#Get New Map Classification
if new_strClassification == "NO CHANGE":
pass
arcpy.AddMessage("NO CLASSIFICATION SPECIFIED")
else:
arcpy.AddMessage("###### MAP CLASSIFICATION SET TO " + new_strClassification + " ######")
#Set Map Classification
for elm in arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT","textClassification"):
elm.text = '<bol>' + new_strClassification + '</bol>'
#If checked remove Classification
if boolStripClassification == True:
for elm in arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT","textClassification"):
elm.text = '<bol>' + "" + '</bol>'
#Classification Color
if str_ClassificationColor == "BLACK":
if new_strClassification == "NO CHANGE":
for elm in arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT","textClassification"):
elm.text = '<CLR black = "100"><bol>' + cleanClassText + '</bol></CLR>'
arcpy.AddMessage("###### MAP CLASSIFICATION SET TO BLACK ######")
else:
for elm in arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT","textClassification"):
elm.text = '<CLR black = "100"><bol>' + new_strClassification + '</bol></CLR>'
arcpy.AddMessage("###### MAP CLASSIFICATION SET TO BLACK ######")
elif str_ClassificationColor == "RED":
if new_strClassification == "NO CHANGE":
for elm in arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT","textClassification"):
elm.text = '<CLR red = "255"><bol>' + cleanClassText + '</bol></CLR>'
arcpy.AddMessage("###### MAP CLASSIFICATION SET TO RED ######")
else:
for elm in arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT","textClassification"):
elm.text = '<CLR red = "255"><bol>' + new_strClassification + '</bol></CLR>'
arcpy.AddMessage("###### MAP CLASSIFICATION SET TO RED ######")
elif str_ClassificationColor == "":
arcpy.AddMessage("NO MAP CLASSIFICATION COLOR SPECIFIED")
pass
#==[ M A P E X P O R T ]===========================================================================#
#Quick Export Checkbox and Workspace
if arcpy.GetParameter(6) == True:
arcpy.mapping.ExportToJPEG(mxd, r"strQuickExportWorkspace")
else:
pass
arcpy.AddMessage("NO EXPORT SPECIFIED")
3. #==[ E X T E N T T O N E A R E S T C I T Y ]===================================================#
#Get to the 'choppa (extent)
if str_NearestCity == "":
pass
arcpy.AddMessage("NO NEAREST CITY SPECIFIED")
else:
if str_MgrsGrid != "":
arcpy.AddMessage("!!!!!!! MGRS GRID WILL OVERRIDE NEAREST CITY !!!!!!!")
else:
arcpy.AddMessage("###### NEAREST CITY SET TO " + str_NearestCity + "IN PROVINCE " + str_NearestCityProv + "
######")
sql_NearestStatement = """ "NAME" = '""" + str_NearestCity + "'" + """ AND "PROV" = '""" + str_NearestCityProv +
"""'"""
arcpy.AddMessage("SEARCH STRING " + sql_NearestStatement)
pPN = arcpy.mapping.ListLayers(mxd, "pt_pPN", dfMain)[0]
arcpy.SelectLayerByAttribute_management(pPN, "NEW_SELECTION", sql_NearestStatement)
dfMain.extent = pPN.getSelectedExtent()
#==[ E X T E N T T O M G R S ]===================================================================#
#Set Map Extent to MGRS
if str_MgrsGrid == "": #Check if MGRS Name and Grid are empty
pass
arcpy.AddMessage("NO MGRS GRID SPECIFIED")
else:
arcpy.AddMessage("###### MGRS GRID SPECIFIED ######")
new_imTbl = arcpy.management.CreateTable("in_memory", "MGRS") #Create in_memory Table
arcpy.AddMessage("CREATING in_memory TABLE...")
tbl_imMgrs = "in_memoryMGRS" #Name in_memory Table
arcpy.AddField_management(tbl_imMgrs, "MGRS", "TEXT") #Add fields to in_memory Table
cursor = arcpy.da.InsertCursor(tbl_imMgrs,("ObjectID", "MGRS")) #Add data to in_memory Table
for x in xrange(0, 1):
cursor.insertRow((x, str_MgrsGrid))
tbl_MgrsAdressLocator = "Address LocatorsMGRS" #Name in_memory Table
arcpy.AddMessage("GEOCODING in_memory SHAPE FILE...")
arcpy.GeocodeAddresses_geocoding(tbl_imMgrs, tbl_MgrsAdressLocator, #Geocode table to pt_imMgrsPoint.shp
"MGRS MGRS VISIBLE NONE",
"in_memorypt_imMgrsPoint.shp")
pt_imMgrsPoint = "in_memorypt_imMgrsPoint.shp" #Name pt_imMgrsPoint.shp
arcpy.MakeFeatureLayer_management(pt_imMgrsPoint, #Make pt_imMgrsPoint.shp a layer
"in_memorylyr_imMgrsPoint")
lyr_imMgrsPoint = "in_memorylyr_imMgrsPoint" #Name new pt_imMgrsPoint layer
arcpy.AddMessage("ADDING NEW GEOCODED SHAPE FILE TO MXD...")
add_imMgrsPoint = arcpy.mapping.Layer(lyr_imMgrsPoint) #Add new pt_imMgrsPoint layer
arcpy.mapping.AddLayer(dfMain, add_imMgrsPoint, "BOTTOM")
pMG = arcpy.mapping.ListLayers(mxd, "in_memorylyr_imMgrsPoint", #Grab pt_imMgrsPoint layer
dfMain)[0]
arcpy.AddMessage("ZOOMING TO GEOCODED SHAPE FILE...")
ext_pMG = pMG.getExtent() #Get pt_imMgrsPoint extent
dfMain.extent = ext_pMG #Move extent to pt_imMgrsPoint layer
arcpy.AddMessage("KILLING GEOCODED SHAPE FILE *BANG*...")
arcpy.mapping.RemoveLayer(dfMain, pMG) #Remove in_memory pt_imMgrsPoint.shp and
pt_imMgrsPoint layer
#==[ S C A L E S E T T I N G S ]===================================================================#
#Scale settings bro
#Set Map Scale
if int_CustomScale != "" and str_MapScale != "CUSTOM":
arcpy.AddMessage("!!!!!!! CUSTOM AND PRESET SCALES SET - " #Check custom scale not set
"DEFAULTING TO CUSTOM !!!!!!!")
arcpy.AddMessage("SCALE SET TO " + int_CustomScale)
dfMain.scale = int_CustomScale #Custom Scale
elif int_CustomScale != "" and str_MapScale == "CUSTOM":
arcpy.AddMessage("SCALE SET TO " + int_CustomScale)
dfMain.scale = int_CustomScale
elif int_CustomScale == "" and str_MapScale == "CUSTOM" :
arcpy.AddMessage("NO CUSTOM SCALE SPECIFIED, KEEPING ORIGINAL SCALE")
dfMain.scale = dfMainCurrentScale
else: #Else preset scale
if str_MapScale == "MACRO - 1:75,000":
arcpy.AddMessage("MACRO - 1:75,000 SPECIFIED") #Macro 75k
dfMain.scale = 75000
elif str_MapScale == "MICRO - 1:5000":
arcpy.AddMessage("MICRO - 1:5,000 SPECIFIED") #Micro 5k
dfMain.scale = 5000
elif str_MapScale == "TOPO - 1:50,000":
arcpy.AddMessage("TOPO - 1:50,000 SPECIFIED") #Topo 50k
dfMain.scale = 50000
elif str_MapScale == "TOPO - 1:25,000":
arcpy.AddMessage("TOPO - 1:25,000 SPECIFIED") #Topo 25k
dfMain.scale = 25000
4. #==[ S H O W L A Y E R S ]=========================================================================#
for lyrOn in arcpy.mapping.ListLayers(mxd):
lyrOn.visible = True
#==[ R E F R E S H T H E M A P ]=================================================================#
#LAST ACTION Refresh Page
arcpy.RefreshActiveView()
arcpy.RefreshTOC()
#==[ E N D ]=========================================================================================#
arcpy.AddMessage(" .. .,")
arcpy.AddMessage(" | | / /")
arcpy.AddMessage(" | | / /")
arcpy.AddMessage(" | | / /")
arcpy.AddMessage(" | |/ ;-._ ")
arcpy.AddMessage(" } ` _/ / ;")
arcpy.AddMessage(" | /` ) / /")
arcpy.AddMessage(" | / /_/_/"")
arcpy.AddMessage(" |/ / |")
arcpy.AddMessage(" ( ' '- |")
arcpy.AddMessage(" `. /")
arcpy.AddMessage(" | |")
arcpy.AddMessage(" CHIMO | |")
time.sleep(3)