Overwrite output in python?

973
1
07-31-2020 08:44 AM
DryCreekEng
Occasional Contributor

I am writing code to cycle through tile packages and publish them to ArcGIS Online. I have tried sticking "arcpy.env.overwriteOutput = True" in a few different places but it doesnt work. The code halts when it finds a duplicate in the output location (here AGOL). 

Please tell me where it is supposed to go, or if I should use something else like asking if the file exists first. 

from arcgis.gis import GIS
import os
import getpass
import arcpy
import sys

gis = GIS("xxx", "xxx", "xxx")
arcpy.env.overwriteOutput = True
arcpy.env.workspace = r'C:\Users\natb0\OneDrive - drycreekeng.com\GIS\GIS\Data\Dry_Creek\7000_CLS_Farms\drone_flight_072720\TilePackages'
workspace = arcpy.env.workspace

for p in arcpy.ListFiles("*"):
 print (p[:-5])
 data_file_location = workspace + "\\" + p
 tile_package = { 'title': ('%s') % p[:-5], 'tags': 'Drone, Imagery', 'type': 'Tile Package'}
 add_tile_package = gis.content.add(tile_package, data = data_file_location)
 publish_tile_package = add_tile_package.publish()
 arcpy.env.overwriteOutput = True 
 publish_tile_package.move(folder= 'Drone')
0 Kudos
1 Reply
NicholasKlein-Baer
New Contributor III

I don't think arcpy.env.overwriteOutput will work - arcpy and the 'ArcGIS API for Python' are not the same thing

this might be useful Overwrite existing Tile Layer Service on ArcGIS Online . There is an answer from KGerrow a ways down that has an example script

maybe try something like:

 tile_package = { 'title': ('%s') % p[:-5], 'tags': 'Drone, Imagery', 'type': 'Tile Package', overwrite': 'true'}

not sure if that would work, only looked at their script very briefly. But i think digging in to that post will send you in the right direction hopefully