import arcpy, os from datetime import date, datetime import time from timeit import default_timer as timer # ## Set a bunch of variables StartTime = datetime.now() start = timer() today = date.today() d1 = today.strftime("%Y%m%d") now = datetime.now() seconds = now.strftime("%S") milliseconds = (seconds * 10) # Current Time Time = time.strftime("%I:%M:%S %p", time.localtime()) # Current Day Day = time.strftime("%m-%d-%Y", time.localtime()) # Create the logging file txtFile = open("c:\SGT\Logs\ChangeSrcURL-azz.txt", "a") print('Count Feature classes: ' + str(Day) + " " + str(Time)) txtFile.write('#####################################################################################' + "\n") txtFile.write('Change Enterprise URLs started at: ' + str(Day) + " " + str(Time) + "\n") txtFile.write('#####################################################################################') txtFile.write("\n") txtFile.close() oldURL = 'https://maps.ci.janesville.wi.us/server/rest/services/Land_Records/Land_Records/FeatureServer' newURL = 'https://tinkerbell-az.ci.janesville.wi.us/server/rest/services/Land_Records/Land_Records/FeatureServer' # ## sets some variables and the output path for the created .lyrx files aprfilenew = r'c:\SGT\TINKER2019-ResourceNoUtil89.aprx' # ## Set your ArcGIS Project to excute the code on. # ##aprfilein = r'C:\Users\tomlinss\Documents\ArcGIS\Projects\ManualResource_udog_2_tinker\ReadSources.aprx' aprfilein = r'c:\SGT\TINKER2019-ResourceNoUtil31.aprx' p = arcpy.mp.ArcGISProject(aprfilein) # ## Create lists for "Maps" and "Layers" in the .aprx cnt=1 aprx = arcpy.mp.ArcGISProject(aprfilein) # Search all layers for the old URL for m in aprx.listMaps(): for lyr in m.listLayers(): if lyr.supports("DATASOURCE"): print(str(lyr) + '....lyr supports connectionProperties') txtFile = open("c:\SGT\Logs\ChangeSrcURL-azz.txt", "a") txtFile.write(arcpy.GetMessages()) txtFile.write("\n") if oldURL in lyr.dataSource: print('attempting to change the oldURL to a newURL') #txtFile = open("c:\SGT\Logs\ChangeSrcURL-azz.txt", "a") txtFile.write(arcpy.GetMessages()) txtFile.write("\n") lyr.updateConnectionProperties(oldURL, newURL) print(arcpy.GetMessages()) print('................') #txtFile = open("c:\SGT\Logs\ChangeSrcURL-azz.txt", "a") txtFile.write(arcpy.GetMessages()) txtFile.write("\n") txtFile.close() # ## Save a copy of the .aprx used in the code above. print("Saving a copy of the aprx to :" + str(aprfilenew)) p.saveACopy(aprfilenew) # EndTime = datetime.now() print("Finished in %s seconds" % (EndTime - StartTime)) print("Elapsed ", (EndTime - StartTime).total_seconds() * 10 ** 6, "us") # print(Style.BRIGHT + Back.LIGHTBLUE_EX + Fore.BLACK + 'This is number of total iterations: ' + str(cnt5)) # print(Style.BRIGHT + Back.LIGHTBLUE_EX + Fore.BLACK + str(cnt) + ' is the total number of records looped thru..!') print("OK.....Completed the task. ") # txtFile.write('The path variable is: ' + path) txtFile = open("c:\SGT\Logs\ChangeSrcURL-az.txt", "a") txtFile.write("\n") txtFile.write('Finished in %s seconds' % (EndTime - StartTime)) txtFile.write("\n") txtFile.close() print (".") print ("..") print ("...")