SlideShare a Scribd company logo
1 of 4
#==[ 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 ]=========================================================================#
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")
#==[ 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
#==[ 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)

More Related Content

What's hot

ggplot2 extensions-ggtree.
ggplot2 extensions-ggtree.ggplot2 extensions-ggtree.
ggplot2 extensions-ggtree.Dr. Volkan OBAN
 
How fast ist it really? Benchmarking in practice
How fast ist it really? Benchmarking in practiceHow fast ist it really? Benchmarking in practice
How fast ist it really? Benchmarking in practiceTobias Pfeiffer
 
Plot3D Package and Example in R.-Data visualizat,on
Plot3D Package and Example in R.-Data visualizat,onPlot3D Package and Example in R.-Data visualizat,on
Plot3D Package and Example in R.-Data visualizat,onDr. Volkan OBAN
 
Some Examples in R- [Data Visualization--R graphics]
 Some Examples in R- [Data Visualization--R graphics] Some Examples in R- [Data Visualization--R graphics]
Some Examples in R- [Data Visualization--R graphics]Dr. Volkan OBAN
 
Extending Operators in Perl with Operator::Util
Extending Operators in Perl with Operator::UtilExtending Operators in Perl with Operator::Util
Extending Operators in Perl with Operator::UtilNova Patch
 
Using R for Building a Simple and Effective Dashboard
Using R for Building a Simple and Effective DashboardUsing R for Building a Simple and Effective Dashboard
Using R for Building a Simple and Effective DashboardAndrea Gigli
 
Clustering com numpy e cython
Clustering com numpy e cythonClustering com numpy e cython
Clustering com numpy e cythonAnderson Dantas
 
Ruby nooks & crannies
Ruby nooks & cranniesRuby nooks & crannies
Ruby nooks & cranniesKerry Buckley
 
Palestra sobre Collections com Python
Palestra sobre Collections com PythonPalestra sobre Collections com Python
Palestra sobre Collections com Pythonpugpe
 
Exploring Canvas
Exploring CanvasExploring Canvas
Exploring CanvasKevin Hoyt
 

What's hot (18)

Mosaic plot in R.
Mosaic plot in R.Mosaic plot in R.
Mosaic plot in R.
 
ggplot2 extensions-ggtree.
ggplot2 extensions-ggtree.ggplot2 extensions-ggtree.
ggplot2 extensions-ggtree.
 
R meets Hadoop
R meets HadoopR meets Hadoop
R meets Hadoop
 
Introduction to R
Introduction to RIntroduction to R
Introduction to R
 
How fast ist it really? Benchmarking in practice
How fast ist it really? Benchmarking in practiceHow fast ist it really? Benchmarking in practice
How fast ist it really? Benchmarking in practice
 
Plot3D Package and Example in R.-Data visualizat,on
Plot3D Package and Example in R.-Data visualizat,onPlot3D Package and Example in R.-Data visualizat,on
Plot3D Package and Example in R.-Data visualizat,on
 
Intoduction to php arrays
Intoduction to php arraysIntoduction to php arrays
Intoduction to php arrays
 
Some Examples in R- [Data Visualization--R graphics]
 Some Examples in R- [Data Visualization--R graphics] Some Examples in R- [Data Visualization--R graphics]
Some Examples in R- [Data Visualization--R graphics]
 
Oh Composable World!
Oh Composable World!Oh Composable World!
Oh Composable World!
 
Extending Operators in Perl with Operator::Util
Extending Operators in Perl with Operator::UtilExtending Operators in Perl with Operator::Util
Extending Operators in Perl with Operator::Util
 
Using R for Building a Simple and Effective Dashboard
Using R for Building a Simple and Effective DashboardUsing R for Building a Simple and Effective Dashboard
Using R for Building a Simple and Effective Dashboard
 
Joclad 2010 d
Joclad 2010 dJoclad 2010 d
Joclad 2010 d
 
Clustering com numpy e cython
Clustering com numpy e cythonClustering com numpy e cython
Clustering com numpy e cython
 
Ruby nooks & crannies
Ruby nooks & cranniesRuby nooks & crannies
Ruby nooks & crannies
 
Codigos
CodigosCodigos
Codigos
 
Palestra sobre Collections com Python
Palestra sobre Collections com PythonPalestra sobre Collections com Python
Palestra sobre Collections com Python
 
Exploring Canvas
Exploring CanvasExploring Canvas
Exploring Canvas
 
Python lists
Python listsPython lists
Python lists
 

Similar to py_AutoMapMaker

Perl6 Regexen: Reduce the line noise in your code.
Perl6 Regexen: Reduce the line noise in your code.Perl6 Regexen: Reduce the line noise in your code.
Perl6 Regexen: Reduce the line noise in your code.Workhorse Computing
 
(BDT401) Big Data Orchestra - Harmony within Data Analysis Tools | AWS re:Inv...
(BDT401) Big Data Orchestra - Harmony within Data Analysis Tools | AWS re:Inv...(BDT401) Big Data Orchestra - Harmony within Data Analysis Tools | AWS re:Inv...
(BDT401) Big Data Orchestra - Harmony within Data Analysis Tools | AWS re:Inv...Amazon Web Services
 
Implementing virtual machines in go & c 2018 redux
Implementing virtual machines in go & c 2018 reduxImplementing virtual machines in go & c 2018 redux
Implementing virtual machines in go & c 2018 reduxEleanor McHugh
 
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011Masahiro Nagano
 
Hacking parse.y (RubyKansai38)
Hacking parse.y (RubyKansai38)Hacking parse.y (RubyKansai38)
Hacking parse.y (RubyKansai38)ujihisa
 
Stupid Awesome Python Tricks
Stupid Awesome Python TricksStupid Awesome Python Tricks
Stupid Awesome Python TricksBryan Helmig
 
Functional programming using underscorejs
Functional programming using underscorejsFunctional programming using underscorejs
Functional programming using underscorejs偉格 高
 
perl usage at database applications
perl usage at database applicationsperl usage at database applications
perl usage at database applicationsJoe Jiang
 
Malli: inside data-driven schemas
Malli: inside data-driven schemasMalli: inside data-driven schemas
Malli: inside data-driven schemasMetosin Oy
 
Damn Fine CoffeeScript
Damn Fine CoffeeScriptDamn Fine CoffeeScript
Damn Fine CoffeeScriptniklal
 
Assignment 5.2.pdf
Assignment 5.2.pdfAssignment 5.2.pdf
Assignment 5.2.pdfdash41
 
A quick introduction to R
A quick introduction to RA quick introduction to R
A quick introduction to RAngshuman Saha
 
Hacking Parse.y with ujihisa
Hacking Parse.y with ujihisaHacking Parse.y with ujihisa
Hacking Parse.y with ujihisaujihisa
 
you need to complete the r code and a singlepage document c.pdf
you need to complete the r code and a singlepage document c.pdfyou need to complete the r code and a singlepage document c.pdf
you need to complete the r code and a singlepage document c.pdfadnankhan605720
 
There's more than one way to empty it
There's more than one way to empty itThere's more than one way to empty it
There's more than one way to empty itAndrew Shitov
 
Perl使いの国のRubyist
Perl使いの国のRubyistPerl使いの国のRubyist
Perl使いの国のRubyistTakafumi ONAKA
 

Similar to py_AutoMapMaker (20)

Perl6 Regexen: Reduce the line noise in your code.
Perl6 Regexen: Reduce the line noise in your code.Perl6 Regexen: Reduce the line noise in your code.
Perl6 Regexen: Reduce the line noise in your code.
 
(BDT401) Big Data Orchestra - Harmony within Data Analysis Tools | AWS re:Inv...
(BDT401) Big Data Orchestra - Harmony within Data Analysis Tools | AWS re:Inv...(BDT401) Big Data Orchestra - Harmony within Data Analysis Tools | AWS re:Inv...
(BDT401) Big Data Orchestra - Harmony within Data Analysis Tools | AWS re:Inv...
 
CLUSTERGRAM
CLUSTERGRAMCLUSTERGRAM
CLUSTERGRAM
 
cluster(python)
cluster(python)cluster(python)
cluster(python)
 
Implementing virtual machines in go & c 2018 redux
Implementing virtual machines in go & c 2018 reduxImplementing virtual machines in go & c 2018 redux
Implementing virtual machines in go & c 2018 redux
 
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
 
Hacking parse.y (RubyKansai38)
Hacking parse.y (RubyKansai38)Hacking parse.y (RubyKansai38)
Hacking parse.y (RubyKansai38)
 
Stupid Awesome Python Tricks
Stupid Awesome Python TricksStupid Awesome Python Tricks
Stupid Awesome Python Tricks
 
Functional programming using underscorejs
Functional programming using underscorejsFunctional programming using underscorejs
Functional programming using underscorejs
 
Polimorfismo cosa?
Polimorfismo cosa?Polimorfismo cosa?
Polimorfismo cosa?
 
perl usage at database applications
perl usage at database applicationsperl usage at database applications
perl usage at database applications
 
Malli: inside data-driven schemas
Malli: inside data-driven schemasMalli: inside data-driven schemas
Malli: inside data-driven schemas
 
Damn Fine CoffeeScript
Damn Fine CoffeeScriptDamn Fine CoffeeScript
Damn Fine CoffeeScript
 
Assignment 5.2.pdf
Assignment 5.2.pdfAssignment 5.2.pdf
Assignment 5.2.pdf
 
A quick introduction to R
A quick introduction to RA quick introduction to R
A quick introduction to R
 
Hacking Parse.y with ujihisa
Hacking Parse.y with ujihisaHacking Parse.y with ujihisa
Hacking Parse.y with ujihisa
 
you need to complete the r code and a singlepage document c.pdf
you need to complete the r code and a singlepage document c.pdfyou need to complete the r code and a singlepage document c.pdf
you need to complete the r code and a singlepage document c.pdf
 
There's more than one way to empty it
There's more than one way to empty itThere's more than one way to empty it
There's more than one way to empty it
 
Perl使いの国のRubyist
Perl使いの国のRubyistPerl使いの国のRubyist
Perl使いの国のRubyist
 
Academy PRO: ES2015
Academy PRO: ES2015Academy PRO: ES2015
Academy PRO: ES2015
 

py_AutoMapMaker

  • 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)