AnsweredAssumed Answered

Python script null/no output in GP Results but is writing the file as expected.

Question asked by LANDVEST on May 2, 2017
Latest reply on May 2, 2017 by LANDVEST

I've created a simple script to share via a web app so that folks without desktop can convert shapes to KML/KMZ. The script writes the output KMZ as expected in the scratch folder where it belongs but doesn't appear in the GP Results window and therefore is a null output when published as a GP Service.

I have a similar script which takes a zip of a multiple shapefiles, reprojects them and zips them back up; this script tool is configured identically and the output zip shows in the GP results and also is returned in the output when published as a GP service.


Script Tool:

Code (not really sure this will help):

import arcpy  
import zipfile
import sys
import os
from os import makedirs
from os.path import join
inZip = arcpy.GetParameterAsText(0)  
# Create a folder in the scratch directory to extract zip to 
outFolder = os.path.join(arcpy.env.scratchFolder, "zipContents") 

# Create a folder in the scratch directory for the KML
KMLfolder = join(arcpy.env.scratchFolder, "KML")
# Extract the zip contents 
zip2Extract = zipfile.ZipFile(inZip, 'r') 

# Set the workspace
arcpy.env.workspace = outFolder

# Create a list of shapefiles
featureclasses = arcpy.ListFeatureClasses()
print featureclasses

# Use ListFeatureClasses to generate a list of inputs
for infc in arcpy.ListFeatureClasses():

    # Determine if the input has a defined coordinate system, can't project if it does not
    dsc = arcpy.Describe(infc)

    if dsc.spatialReference.Name == "Unknown":
        print('skipped this fc due to undefined coordinate system: ' + infc)
        # Make Feature Layer from FC
        tempLayer = arcpy.MakeFeatureLayer_management(infc, "tempLayer")
        # Define KML output
        outKML = os.path.join(KMLfolder, baseName + '.kmz')       
        #Convert Layer to KML
        output = arcpy.LayerToKML_conversion(tempLayer, outKML)