Summary
The Publish function publishes a SceneLayerSharingDraft object as a web scene layer with an associated web feature layer to ArcGIS Online or ArcGIS Enterprise. If you publish a web scene layer that references registered data to ArcGIS Enterprise, an associated map image layer is also included. Once the web scene layer and associated web layers are published, caching starts on the server.
You can use the item_id parameter to specify item IDs for the web scene layer and associated web layers. Item IDs must be available for publishing to be successful. The parameter is honored for web scene layers and web feature layers when sharing to ArcGIS Enterprise 10.8.1 or later. For map image layers, the parameter is honored when sharing to ArcGIS Enterprise 11.2 or later.
Syntax
Publish (object, {item_id})
Parameter | Explanation | Data Type |
object | The SceneLayerSharingDraft object that will be published. | Object |
item_id | An optional dictionary of items IDs that will be honored when publishing. The ID must be available and contain 32 alphanumeric values ranging from the letters a to f and numbers 0 to 9. An item ID will be automatically created if no ID is specified. | Dictionary |
Data Type | Explanation |
Dictionary | Returns a dictionary that includes the item URL, REST URL, and cache job ID. |
Code sample
The following script creates a web scene layer sharing draft for a layer in a scene. Item IDs are specified for the web scene layer and associated web layers. The web scene layer is published to ArcGIS Enterprise. Portal information is obtained from the SignInToPortal function.
import arcpy
# Sign in to portal
arcpy.SignInToPortal("https://organization.example.com/webadaptorname",
"MyUserName", "MyPassword")
# Reference layer to publish
aprx = arcpy.mp.ArcGISProject(r"C:\Project\World.aprx")
m = aprx.listMaps('World')[0]
lyr = m.listLayers('Cities')
# Create SceneLayerSharingDraft
server_type = "FEDERATED_SERVER"
service_type = "SCENE_LAYER"
service_name = "SceneLayerSharingDraftExample"
scene_draft = m.getWebLayerSharingDraft(server_type, service_type, service_name, lyr)
# Publish scene layer using the SceneLayerSharingDraft object and specific item ID
# The ID must be available and contain 32 alphanumeric values ranging from the letters a to f and numbers 0 to 9
item_id = {
"web_scene_layer_id": "itemid1",
"web_feature_layer_id": "itemid2",
"map_image_layer_id": "itemid3"
}
# Share to portal
print("Start Publishing")
res = arcpy.sharing.Publish(scene_draft, item_id)
print(r"item_url: " + res["web_scene_layer"]["item_url"])
print(r"rest_url: " + res["web_scene_layer"]["rest_url"])
print(r"cache_job_id: " + res["web_scene_layer"]["cache_job_id"])
print("Finish Publishing")