ArcGIS Pro批量创建离线服务sd包
import arcpy
import os
# Set output file names
outdir = r"d:\data\out"
pth = r"C:\Users\Priva\Documents\GeoScene\Projects\MyProject23\MyProject23.aprx"
aprx = arcpy.mp.ArcGISProject(pth)
mapnames = []
for i, m in enumerate(aprx.listMaps()):
print(f"{i} : {m.name}")
#mapnames.append(m.name)
service_name = m.name
sddraft_filename = service_name + ".sddraft"
sddraft_output_filename = os.path.join(outdir, sddraft_filename)
sd_filename = service_name + ".sd"
sd_output_filename = os.path.join(outdir, sd_filename)
# Create MapServiceDraft and set metadata and server folder properties
sddraft = arcpy.sharing.CreateSharingDraft("STANDALONE_SERVER", "MAP_SERVICE", service_name, m)
#sddraft.credits = "These are credits"
sddraft.description = "This is description"
sddraft.summary = "This is summary"
sddraft.tags = "tag1, tag2"
#sddraft.useLimitations = "These are use limitations"
#sddraft.serverFolder = "MyServerFolder"
sddraft.offline = True
sddraft.copyDataToServer = True
# Create Service Definition Draft file
sddraft.exportToSDDraft(sddraft_output_filename)
# Stage Service
print("Start Staging")
arcpy.server.StageService(sddraft_output_filename, sd_output_filename)
print("finish")