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:
<SPAN class="c"># Import system modules</SPAN><BR /><SPAN class="kn">import</SPAN> <SPAN class="nn">arcpy</SPAN><BR /><SPAN class="kn">from</SPAN> <SPAN class="nn">arcpy</SPAN> <SPAN class="kn">import</SPAN> <SPAN class="n">env</SPAN><BR /><BR /><SPAN class="c"># Set the current workspace</SPAN><BR /><SPAN class="n">env</SPAN><SPAN class="o">.</SPAN><SPAN class="n">workspace</SPAN> <SPAN class="o">=</SPAN> <SPAN class="s">"file path where layer files are saved"</SPAN><BR /><BR /><SPAN class="c"># Set layer to apply symbology to</SPAN><BR /><SPAN class="n">inputLayer</SPAN> <SPAN class="o">=</SPAN> <SPAN class="s">"layer file name"</SPAN><BR /><BR /><SPAN class="c"># Set layer that output symbology will be based on</SPAN><BR /><SPAN class="n">symbologyLayer</SPAN> <SPAN class="o">=</SPAN> <SPAN class="s">"feature class within map"</SPAN><BR /><BR /><SPAN class="c"># Apply the symbology from the symbology layer to the input layer</SPAN><BR /><SPAN class="n">arcpy</SPAN><SPAN class="o">.</SPAN><SPAN class="n">ApplySymbologyFromLayer_management</SPAN> <SPAN class="p">(</SPAN><SPAN class="n">inputLayer</SPAN><SPAN class="p">,</SPAN> <SPAN class="n">symbologyLayer</SPAN><SPAN class="p">)</SPAN>
This part works fine.
Save the map:
<SPAN class="c"># Set up map variable<BR /></SPAN>
<SPAN class="kwd">import</SPAN><SPAN class="pln"> arcpy</SPAN><SPAN class="pun">.</SPAN><SPAN class="pln">mapping </SPAN><SPAN class="kwd">as</SPAN><SPAN class="pln"> map<BR /></SPAN>
<SPAN class="pln"># Set map variable to current mxd<BR />mxd </SPAN><SPAN class="pun">=</SPAN><SPAN class="pln"> map</SPAN><SPAN class="pun">.</SPAN><SPAN class="typ">MapDocument</SPAN><SPAN class="pun">("CURRENT")</SPAN><SPAN class="pln"><BR /></SPAN>
<SPAN class="pln"># Save the map document<BR />mxd</SPAN><SPAN class="pun">.</SPAN><SPAN class="pln">save</SPAN><SPAN class="pun">()</SPAN>
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.