Hi everyone,
I was hoping someone could help me with the tool called Map to KML. I only want to be able to make it go through a folder that contains a bunch of .mxd and have it produce kmz files for each map all in one shot. I have tried to figure this out in Model Builder but I can't find an iterator or anything that will go through a folder with map documents that will be able to run through Map to KML. Any ideas? I'm not very fluent with using python so I want to try and accomplish this through Model Builder if possible.
Thanks
import arcpy import os #This will ask you to set a folder that contains the mxds. This counts as your workspace. #Then it will go through each mxd file in the list, and will run Map to KML on them using the variables set out in the for loop. mxdfolder = arcpy.GetParameterAsText(0) arcpy.env.workspace = mxdfolder if len(arcpy.ListFiles('*.mxd')) > 0: for mxd in arcpy.ListFiles('*.mxd'): dataFrame = 'Layers' outKML = mxd[:-4]+'.kmz' arcpy.MapToKML_conversion(mxd, dataFrame, outKML) else: arcpy.AddMessage('There are no map documents (*.mxd) in '+env.workspace)
In the end I forgot to close this down but the above code is what I ended up with and it works perfectly
Thanks!
Cool! That will work, thanks!
Colin Berg
Mapping Technician
T: 403.295.0694
F: 403.295.2444
E: colin.berg@nwgeo.com<mailto:colin.berg@nwgeo.com>
North West Geomatics Ltd.
245 Aero Way NE
Calgary, AB T2E 6K2
www.nwgeo.com<http://www.nwgeo.com/>
North West is a part of HEXAGON.
I see that Iterate Files does not work on mxd files. I think your only solution is to use Python in a Calculate Value tool. Fortunately this isn't that hard. Here is an untested Calculate Value setup based on the example code provided in the help for the Map to KML tool.
This requires that you have a model variable MXD folder with the folder location where the MXD files are (and where the kmzs are created).
<SPAN class="comment token"># Calculate Value expression</SPAN> <SPAN class="comment token"># ff(r"%MXD folder%")</SPAN> <SPAN class="comment token"># Calculate Value code block</SPAN> <SPAN class="keyword token">import</SPAN> os <SPAN class="keyword token">import</SPAN> arcpy <SPAN class="keyword token">def</SPAN> <SPAN class="token function">ff</SPAN><SPAN class="punctuation token">(</SPAN>mxdfolder<SPAN class="punctuation token">)</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>workspace <SPAN class="operator token">=</SPAN> mxdfolder <SPAN class="keyword token">for</SPAN> mxd <SPAN class="keyword token">in</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>ListFiles<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'*.mxd'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="comment token"># Set Local Variables</SPAN> dataFrame <SPAN class="operator token">=</SPAN> <SPAN class="string token">'Layers'</SPAN> composite <SPAN class="operator token">=</SPAN> <SPAN class="string token">'NO_COMPOSITE'</SPAN> vector <SPAN class="operator token">=</SPAN> <SPAN class="string token">'VECTOR_TO_VECTOR'</SPAN> pixels <SPAN class="operator token">=</SPAN> <SPAN class="number token">2048</SPAN> dpi <SPAN class="operator token">=</SPAN> <SPAN class="number token">96</SPAN> clamped <SPAN class="operator token">=</SPAN> <SPAN class="string token">'ABSOLUTE'</SPAN> <SPAN class="keyword token">for</SPAN> scale <SPAN class="keyword token">in</SPAN> range<SPAN class="punctuation token">(</SPAN><SPAN class="number token">10000</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">30001</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">10000</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="comment token"># Strips the '.mxd' part of the name and appends '.kmz'</SPAN> outKML <SPAN class="operator token">=</SPAN> mxd<SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="operator token">-</SPAN><SPAN class="number token">4</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="operator token">+</SPAN><SPAN class="string token">'.kmz'</SPAN> <SPAN class="comment token">#Execute MapToKML</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>MapToKML_conversion<SPAN class="punctuation token">(</SPAN>mxd<SPAN class="punctuation token">,</SPAN> dataFrame<SPAN class="punctuation token">,</SPAN> outKML<SPAN class="punctuation token">,</SPAN> scale<SPAN class="punctuation token">,</SPAN> composite<SPAN class="punctuation token">,</SPAN> vector<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">''</SPAN><SPAN class="punctuation token">,</SPAN> pixels<SPAN class="punctuation token">,</SPAN> dpi<SPAN class="punctuation token">,</SPAN> clamped<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">return</SPAN> <SPAN class="token boolean">True</SPAN> <SPAN class="comment token"># Calculate Value data type - True (1) if Calculate Value executes OK</SPAN> <SPAN class="comment token"># Boolean</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Les membres connectés peuvent publier, suivre les mises à jour, et plus encore. Nouveau ici ? Inscrivez-vous gratuitement.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.