Hello,
I'm having a bit of an issue with zipping up a shapefile on ArcGIS Server from calling a GP tool with WAB.
My code is below. It works for kmz and excels but having some trouble with the zipping and shpfile part.
This is what gets outputted by the tool
https://xyz.com/server/rest/directories/arcgisjobs/gp/export/j0ba310e06ab92dsdsde8f71690faba/scratch/scratch.zip
That link is invalid, however when I change it to (remove the extra scratch at the end)
https://xyz.com/server/rest/directories/arcgisjobs/gp/export/j0ba310e06ab92dsdsde8f71690faba/scratch.zip
It works, but then when I look in there, there is a scratch.gdb with nothing in it. When I run this in ArcMap it does produce the scratch.zip with the shpfile in it. C:\Users\adam\Documents\ArcGIS\scratch.zip
featureLayer <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>GetParameter<SPAN class="punctuation token">(</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">)</SPAN>
outputFormat <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>GetParameterAsText<SPAN class="punctuation token">(</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">if</SPAN> outputFormat <SPAN class="operator token">==</SPAN> <SPAN class="string token">".kmz (Google Earth)"</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">try</SPAN><SPAN class="punctuation token">:</SPAN>
kmzFile <SPAN class="operator token">=</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN>arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>scratchFolder<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"export.kmz"</SPAN><SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>MakeFeatureLayer_management<SPAN class="punctuation token">(</SPAN>featureLayer<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"in_memory\layer"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token">#arcpy.ApplySymbologyFromLayer_management("in_memory\layer",lyr)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>LayerToKML_conversion<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"in_memory\layer"</SPAN><SPAN class="punctuation token">,</SPAN> kmzFile<SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>AddMessage<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Success. You can find the kmz in the link below"</SPAN><SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>AddMessage<SPAN class="punctuation token">(</SPAN>kmzFile<SPAN class="punctuation token">)</SPAN>
outputName <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>SetParameterAsText<SPAN class="punctuation token">(</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">,</SPAN>kmzFile<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">except</SPAN><SPAN class="punctuation token">:</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>AddMessage<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Error exporting kmz"</SPAN><SPAN class="punctuation token">)</SPAN>
sys<SPAN class="punctuation token">.</SPAN>exit<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">if</SPAN> outputFormat <SPAN class="operator token">==</SPAN> <SPAN class="string token">".xls (Excel)"</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">try</SPAN><SPAN class="punctuation token">:</SPAN>
excelFile <SPAN class="operator token">=</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN>arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>scratchFolder<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"export.xls"</SPAN><SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>TableToExcel_conversion<SPAN class="punctuation token">(</SPAN>featureLayer<SPAN class="punctuation token">,</SPAN> excelFile<SPAN class="punctuation token">)</SPAN>
outputName <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>SetParameterAsText<SPAN class="punctuation token">(</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">,</SPAN>excelFile<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">except</SPAN><SPAN class="punctuation token">:</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>AddMessage<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Error exporting kmz"</SPAN><SPAN class="punctuation token">)</SPAN>
sys<SPAN class="punctuation token">.</SPAN>exit<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">if</SPAN> outputFormat <SPAN class="operator token">==</SPAN> <SPAN class="string token">".shp (Shapefile)"</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="comment token">#shpFile = os.path.join(arcpy.env.scratchFolder, "export.shp") </SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>AddMessage<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"shp file"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token">#createFolder(outFolder + r'\data')</SPAN>
<SPAN class="comment token">#a = outFolder + r'\data'</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>FeatureClassToShapefile_conversion<SPAN class="punctuation token">(</SPAN>featureLayer<SPAN class="punctuation token">,</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>scratchFolder<SPAN class="punctuation token">)</SPAN>
shutil<SPAN class="punctuation token">.</SPAN>make_archive<SPAN class="punctuation token">(</SPAN>arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>scratchFolder<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'zip'</SPAN><SPAN class="punctuation token">,</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>scratchFolder<SPAN class="punctuation token">)</SPAN>
outputFile <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>scratchFolder <SPAN class="operator token">+</SPAN> <SPAN class="string token">".zip"</SPAN>
outputName <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>SetParameterAsText<SPAN class="punctuation token">(</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">,</SPAN> outputFile<SPAN class="punctuation token">)</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></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
