# AUTOMATING LIVEBOARD MAPS FOR COURT # Author: M.Convey - 20.01.2012 # Versions: ArcGIS 10. Python 2.6 # Python script to allow the automatic production of a liveaboard map for the Enforcement team # The user clicks on the script / button and then clicks on the map at the point at which their boat is # The user then completes the attributes presented to them: Boat name, index number, canal, nearest town # After the user has then selected where to save the PDF, clicking GO will begin the script # Changes should not be saved # Import arcpy module import arcpy # Load required toolboxes arcpy.ImportToolbox("G:/GIS_Admin/zNamed_folders/Michelle/Projects/Enforcement/Enforcement_10.tbx") # Workspace arcpy.env.Workspace = r"G:\_Directorate\Marketing\Enforcement\Liveaboard Maps\Liveaboard_Arc10.mdb" wsp = arcpy.env.Workspace # Overwrite Output arcpy.env.overwriteOutput = True # Sets the mxd to the one currently in use mapDoc = arcpy.mapping.MapDocument("CURRENT") # Parameters LiveaboardBoats = r"G:\_Directorate\Marketing\Enforcement\Liveaboard Maps\Liveaboard_Arc10.mdb\LiveaboardBoats" LiveaboardBoatsCopy = r"G:\_Directorate\Marketing\Enforcement\Liveaboard Maps\Liveaboard_Arc10.mdb\LiveaboardBoatsCopy" lyr = r"G:\_Directorate\Marketing\Enforcement\Liveaboard Maps\Boat Location.lyr" # Append the new liveboard to the 'master' copy of the boats so that have a record arcpy.Append_management(LiveaboardBoatsCopy, LiveaboardBoats) # Script arguments # This worked fine in 10: Feature_Set = arcpy.GetParameterAsText(0) if Feature_Set == '#' or not Feature_Set: Feature_Set = "in_memory\\{475E88CB-9AAC-48ED-B772-D04A526AD1F6}" # provide a default value if unspecified # Get pdf file path to create outputPDFPath = arcpy.GetParameterAsText(1) if outputPDFPath == '#' or not outputPDFPath: arcpy.AddError("Cannot proceed without specifying an output path for the pdf file") #return # Copy the feature set to the temporary holding feature class arcpy.CopyFeatures_management (Feature_Set, LiveaboardBoatsCopy) # Fix broken data sources that arise when copy (?) for lyr in arcpy.mapping.ListBrokenDataSources(mapDoc): if lyr.supports("DATASOURCE"): if lyr.dataSource == r"G:\_Directorate\Marketing\Enforcement\Liveaboard Maps\Liveaboard_Arc10.mdb\LiveaboardBoatsCopy": lyr.replaceDataSource(r"G:\_Directorate\Marketing\Enforcement\Liveaboard Maps\Liveaboard_Arc10.mdb", "ACCESS_WORKSPACE", "LiveaboardBoatsCopy") lyr.name = "LiveaboardBoatsCopy" # Do other mapp based stuff here... # Refresh active view arcpy.RefreshActiveView() # Export arcpy.AddMessage(" Saving as PDF") arcpy.mapping.ExportToPDF(mapDoc,outputPDFPath) del mapDoc
Solved! Go to Solution.
class ToolValidator: """Class for validating a tool's parameter values and controlling the behavior of the tool's dialog.""" def __init__(self): """Setup arcpy and the list of tool parameters.""" import arcpy self.params = arcpy.GetParameterInfo() def initializeParameters(self): """Refine the properties of a tool's parameters. This method is called when the tool is opened.""" return def updateParameters(self): """Modify the values and properties of parameters before internal validation is performed. This method is called whenever a parmater has been changed.""" return def updateMessages(self): """Modify the messages created by internal validation for each tool parameter. This method is called after internal validation.""" return
class ToolValidator: """Class for validating a tool's parameter values and controlling the behavior of the tool's dialog.""" def __init__(self): """Setup arcpy and the list of tool parameters.""" import arcpy self.params = arcpy.GetParameterInfo() def initializeParameters(self): """Refine the properties of a tool's parameters. This method is called when the tool is opened.""" return def updateParameters(self): """Modify the values and properties of parameters before internal validation is performed. This method is called whenever a parmater has been changed.""" return def updateMessages(self): """Modify the messages created by internal validation for each tool parameter. This method is called after internal validation.""" return
This is a bug though. Even with tools supplied by ESRI (i.e. Terrain Profile tool), the feature template will work the first time and allow you to draw a line as input. However, any subsequent times after saving the mxd and re-opening it, instead of the draw tool, the select tool will show.
The only way around it, is to copy all layers to a new mxd and re-run the tool....of course this means that you loose a lot of information.
Pretty frustrating to be honest.