Does anyone know how to add a vector tile package (VTPK) to a map using 'arcpy'? I have tried a variety of different syntaxes but my Python code always errors out whether I use the 'addLayer' method or 'addDataFromPath' method.
I have about 500+ VTPK files that I need to 'merge' together and what I'm thinking of doing is creating a mobile map package (MMPK) once I can get them added to a map in an automated way.
Thanks in advance for your help.
Solved! Go to Solution.
Thank you for responding. After playing with the code some more, this ended up working for me:
import arcpy, os
outputLocation = r"C:\TEMP"
aprx = arcpy.mp.ArcGISProject(outputLocation + "/VTPK.aprx")
m = aprx.listMaps("VTPK")[0]
basemap = m.listLayers("Basemap")[0]
for filename in os.listdir(outputLocation):
if filename.endswith(".vtpk"):
lyr = m.addDataFromPath(outputLocation + "/" + filename)
m.addLayerToGroup(basemap, lyr)
aprx.save()
continue
else:
continue
It helps to provide both code and errors. I thought I had used addDataFromPath with VTPK in the past, so I tested it again and it works fine for me.
Thank you for responding. After playing with the code some more, this ended up working for me:
import arcpy, os
outputLocation = r"C:\TEMP"
aprx = arcpy.mp.ArcGISProject(outputLocation + "/VTPK.aprx")
m = aprx.listMaps("VTPK")[0]
basemap = m.listLayers("Basemap")[0]
for filename in os.listdir(outputLocation):
if filename.endswith(".vtpk"):
lyr = m.addDataFromPath(outputLocation + "/" + filename)
m.addLayerToGroup(basemap, lyr)
aprx.save()
continue
else:
continue