ArcPy Batch KML Script

203
4
10-01-2021 10:55 AM
Labels (1)
AdCulver
New Contributor II

Looking for help with my script. I am getting an error on line 11 with ".kmz".

import arcpy

LineList = [381001,
691001]

LayerList = ["Structures","Transmission Circuit"]

for Line in LineList:
for Layer in LayerList:

kmlname = "\\fs01\Inspection Programs\CVI\2021\Inspections\Drone\" + str(Line) + "." + Layer + ".kmz"
sql = "legacycircuitid = '" + str(Line) +"'"
arcpy.management.SelectLayerByAttribute(Layer, 'NEW_SELECTION', sql)
arcpy.conversion.LayerToKML(Layer, kmlname)

4 Replies
DanPatterson
MVP Esteemed Contributor

Code formatting ... the Community Version - Esri Community

will provide line numbers and proper formatting... as it is shown now

Also, kmlname = "\\fs01\Inspection P.....

probably won't work since you haven't set an environment workspace in your script


... sort of retired...
0 Kudos
AdCulver
New Contributor II

Thanks, Dan.

I added in a specified output folder.

LineList = []

LayerList = ["Structures", "Transmission Circuit"]
OutputFolder = "H:\"

print("Preparing files")

for Line in LineList:
for Layer in LayerList:

kmlname = OutputFolder + str(Line) + "." + str(Layer) + ".kmz"
sql = "legacycircuitid = '" + str(Line) +"'"
arcpy.management.SelectLayerByAttribute(Layer, 'NEW_SELECTION', sql)
arcpy.conversion.LayerToKML(Layer, kmlname)
print("KMZ created for " + str(Line) + " " + str(Layer))

I'd like to import this into a gp tool so the engineers can simply specify the ID. 

 

0 Kudos
AdCulver
New Contributor II
import arcpy
LineList = []

LayerList = ["Structures", "Transmission Circuit"]
OutputFolder = "H:\"

print("Preparing files")

for Line in LineList:
    for Layer in LayerList:

        kmlname = OutputFolder + str(Line) + "." + str(Layer) + ".kmz"
        sql = "legacycircuitid = '" + str(Line) +"'"
        arcpy.management.SelectLayerByAttribute(Layer, 'NEW_SELECTION', sql)
        arcpy.conversion.LayerToKML(Layer, kmlname)
        print("KMZ created for " + str(Line) + " " + str(Layer))
DanPatterson
MVP Esteemed Contributor

the last line of my comment... the script as it stands has no clue where to find those layers


... sort of retired...
0 Kudos