I am trying to create a script that will apply a symbology layer to the current map, save the map, export the map to KML, and then reapply the original symbology from a layer file.
Apply symbology from layer file:
# Import system modules
import arcpy
from arcpy import env
# Set the current workspace
env.workspace = "file path where layer files are saved"
# Set layer to apply symbology to
inputLayer = "layer file name"
# Set layer that output symbology will be based on
symbologyLayer = "feature class within map"
# Apply the symbology from the symbology layer to the input layer
arcpy.ApplySymbologyFromLayer_management (inputLayer, symbologyLayer)
This part works fine.
Save the map:
# Set up map variable
import arcpy.mapping as map
# Set map variable to current mxd
mxd = map.MapDocument("CURRENT")
# Save the map document
mxd.save()
This part works fine.
Map to KML:
# Set environment settings
arcpy.env.workspace = "haven't figured this part out yet"
# Set Local Variables
dataFrame = 'Layers'
# Sets the KMZ name to be equal to the mxd
outKML = mxd+'.kmz'
#Execute MapToKML
arcpy.MapToKML_conversion(mxd, dataFrame, outKML)
This is the part that I'm having trouble with. I'm not entirely sure how to correctly construct the Map to KML portion. This script will be run on many different maps and the workspace for each map will be identical to each other with the exception of the map name. I tried to set the workspace to the following path, with no luck:
arcpy.env.workspace = "folder1\folder2\folder3\" + mxd + "\folder4\folder5"
But this results in this error "Parsing error SyntaxError: unexpected character after line continuation character (line 1)
Apply symbology from layer file:
Simply a repeat of the previous iteration of the tool with a different layer file.