Layer to KML works in Python window but not in Script tool [Update: Bug]

420
5
Jump to solution
03-27-2020 06:22 AM
ZacharyHart
Regular Contributor

ArcGIS Pro 2.5

The Layer to KML GP Tool from the standard TBX works fine.

The ArcPy code will work in the Python window.

The ArcPy code will even run and produce the KMZ from an IDE (such as Spyder).

The ArcPY code completes without error when run as a Script Tool in Pro, but no output is produced.

Can anyone else test this? I'm losing my mind trying to figure this out.

import arcpy

arcpy.env.overwriteOutput = True

arcpy.MakeFeatureLayer_management(r"C:\Users\JackTorrance\Documents\ArcGIS\scratch\export\ExportTestAgain333.shp", "ExportedFeaturesLayer")
arcpy.AddMessage(arcpy.GetCount_management("ExportedFeaturesLayer").getOutput(0))
arcpy.LayerToKML_conversion("ExportedFeaturesLayer", "D:\\TEMP\\TryThis.kmz")‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

I added the message simply to ensure the feature layer was valid (contains features), and you can see this working as expected in the GP messaging dialog.

One other observation: the script tool takes way longer than it should, like 2.5 minutes!

0 Kudos
1 Solution

Accepted Solutions
ZacharyHart
Regular Contributor

From Support Services:

We finished the testing and confirmed and attached the following defect to your case:

BUG-000129805 : Running the python command for  Layer to KML works in idle, but fails to create output if run from script tool.

Lame. We are in the process of updating all of our existing GP services to Pro/Python 3.x based tools. This roadblocks updating one of our most used GP widgets which will now have to remain ArcMap/Python 2.x based for the foreseeable future.

View solution in original post

0 Kudos
5 Replies
DanPatterson_Retired
MVP Esteemed Contributor

script tool ... as in a script attached to a tool in a toolbox?

what are the parameters you have specified?

Conventional script tools require that the parameters be specified as input, derived or output.

The code you have posted seems to be that used in an IDE which should work there as you have found

0 Kudos
ZacharyHart
Regular Contributor

Hi Dan,

I dumbed th code way down for purpose of isolation. No parameters set in the script tool for this test. I have tried a number of different input types and output locations.

Humor me and toss that in a script tool and let me know if it works for you. This may be a bug.

0 Kudos
DanPatterson_Retired
MVP Esteemed Contributor

/blogs/dan_patterson/2016/05/19/toolbox-creation-in-arcgis-pro 

I would have to rewrite your code to specify your hardcoded paths to work in a conventional python tool

0 Kudos
ZacharyHart
Regular Contributor

Dan, I tossed this into a script tool with the script imported. The TBX is zipped and attached above. The output location will be a folder called 'export' in your scratch folder. Thanks!

0 Kudos
ZacharyHart
Regular Contributor

From Support Services:

We finished the testing and confirmed and attached the following defect to your case:

BUG-000129805 : Running the python command for  Layer to KML works in idle, but fails to create output if run from script tool.

Lame. We are in the process of updating all of our existing GP services to Pro/Python 3.x based tools. This roadblocks updating one of our most used GP widgets which will now have to remain ArcMap/Python 2.x based for the foreseeable future.

0 Kudos