ArcGIS Pro v2.9.2 crashes when using "Layer To KML" in script tool

05-10-2022 11:57 AM
Labels (1)
New Contributor III

Using the geoprocessing tool, "Layer To KML" within a python script tool and ArcGIS Pro v2.9.2 crashes without warning, or error(s). If the tool is used outside of the script tool, there is no problem and KMZ is created as expected. No screen shots available but my code is as follows:

arcpy.LayerToKML_conversion(out_layer, "MergedShape.kmz")

Seems straight forward enough but crashes everytime.

3 Replies
Esri Contributor

Hi @JamesShively, I'm unable to reproduce your crash, although I might be doing something different from you. Here's the script I'm using for the tool execution:




import os
import arcpy

in_lyr = arcpy.GetParameterAsText(0)
out_kmz_path = arcpy.GetParameterAsText(1)
out_kmz_name = arcpy.GetParameterAsText(2)
out_kmz = os.path.join(
  out_kmz_name if out_kmz_name.endswith(".kmz") else f"{out_kmz_name}.kmz" 

def execute(in_lyr, out_kmz_path):
  res = arcpy.conversion.LayerToKML(in_lyr, out_kmz)
  return res

output = execute(in_lyr, out_kmz_path)
arcpy.SetParameter(3, output)




And for the script tool are set up like this:


I tried it in 2.9 and 2.9.2

0 Kudos
New Contributor

Hello, I find that I'm running in to the same error as @JamesShively. I am also using ArcGIS Pro 2.9 (2.9.5, in my case). My script tool converts a KMZ file to a layer, projects it to a UTM of the user's choice, splits the line into segments from the vertices, generates points along the line segments, merges the point feature classes, projects the merged points back to WGS 1984 (then produces a layer for the KMZ tool input), and finally attempts to convert that point layer to a KMZ file.

I can track the progress of the script tool up to the point where it tries to convert the projected points to a KMZ file, then ArcGIS Pro crashes. All intermediate feature classes are produced successfully and seem to have correct geometry and projections. I've taken pains to mimic your parameter setup and execute function code block in my script, but I regret that it's still failing. What puzzles and perplexes me is that if I use the same code blocks and defined variables within the Python window of ArcGIS Pro, the KMZ file is produced instantly. If you have the time, could you please let me know if you have any other suggestions for me to try?

0 Kudos
New Contributor

For anyone still seeking an answer to this issue, my workflow required that I use the tool GeneratePointsAlongLines() to produce points, which I eventually wanted to convert to .kmz files. ArcGIS Pro crashed consistently if I used the script in a script tool or if I ran the script with an editor, but I did find a workaround. I produced buffers around each of the points, then converted those buffers to points (with centroids) before converting the resulting layer to .kmz files. I don't have a clear understanding of the reason that this allowed the script to proceed successfully, but I hope this might help anyone else struggling with the same issue.

0 Kudos