This script can be used to execute the workflow - converting a Revit building model into Building Scene Layer package then upload it into ArcGIS Online server and publish it as Scene Layer (Hosted)
This code is meant to be a starting work-frame from which you can develop your pipeline in similar or related workflows.
It still can be used to execute the exact workflow mentioned, however for it to run you need to be automatically logged in in ArcGIS Pro. Otherwise, you should adjust the code in the Authentication part to grant access to ArcGIS Online content. For more information about the workflow and the code, refer to this Story Map.
Moreover, the repository contains a Python script toolbox (geoprocessing toolbox). This is created and derived using the same Python script and can be used directly in ArcGIS Pro to run the same worflow. For more details about the toolbox, refer to the following blog
- This file README.md
- LICENCE
- A Python file named
BIMpublication# this is the main Python Script that can be used direcly or modified to fit your workflow - A (.bat) file named
runPythonScript#this can be used for automating using Task Scheduler - A txt file named
TimesLog.txt#this file is used for the helper function checkDateFunction() - A toolbox named
BIMpublicationToolbox#this toolbox (the script is embedded) can be used directly in ArcGIS Pro and it runs the exact workflow mentioned above. - A Python file named
BIMpublicationScriptToolVerssion#this script is a copy of BIMpublication.py, however it is adjusted to be read by the toolbox. This file can be used to develop the Geoprocessing tool to fit your workflow if you wish to. - Internship report.PDF
- Check if a revit file has been modifed since the last run #optional: using helper function
- Creating geodatabase folder in your local machine
- Importing Revit data into the geodatabase created
- If desired making some changes
- Making Building Layer
- Creating Building Scene Layer Package (.slpk)
- Uploading (or updating) the created Building Scene Layer Package (.slpk file) into ArcGIS Online
- Finally, publishing (or replacing) it as Scene Layer (Hosted)
Required
- workSpaceEnv = r"C:\user\AutoFolder" #path to a folder in which a .gdb file is created
- Rvt_directory = r"C:\Users\Berging.rvt" #path to rvt file
- BSL_name = r"BSLpackage.slpk" #defaul is BSLpackage.slpk
- spatial_reference = r"RD New" #default is "RD New"
- nameOfBuildingL = r"BuildL_A" #this name will show on the ArcGIS online
Optional
- out_FeatureDataset= r"Building_A" #default "Building_A"
- includeDate = False #Include date of the day in the returned slpk file e.g. (name20202112.slpk)
Required
- DirectoryTo_SLPK = None # if not provided the script will try derive it from the arguments of function 1 (if provided)
- itemID_BSLp = "itemID" # if not provided the program will simply upload the Building Scene Layer Package provided
- itemID_Hosted= "itemID" # if not provided the program will search for Scene Layer that holds the same name and replace it. If not found it will publish a new one. In this blog you can find a tutorial on how to get an item_id from ArcGIS Online.
- dictOfPackageLayer = #dictionary: Value Dictionary Options for the item_properties argument:
example: {"overwrite" : True, "tags" : ["ArcGIS", "BuildingSceneLayer", "revit"], "snippet": "Here goes the description about your Building Scene Layer Package"}
overwrite parameter is importatnt to be set on True ##Only change if you know what you are doing; here you can find full explaination on the values that can be used## This dictionary can be used to update the Building Scene Layer Pckage/Scene Layer (Hosted) item_properties details/information such as title, tags etc. However, it is advised to use Update() method as it performs faster after publishing.
import BIMpublication
# create building scene layer function
# Required
##########
workSpaceEnv = r"C:\Users\username\Desktop\AutomationTest"
Rvt_directory = r"C:\Users\username\Desktop\AutomationTest\revitFiles\171025_BLOKA.rvt"
BSL_name = r"BSLpackage.slpk"
spatial_reference = r"RD New"
nameOfBuildingL = r"BuildL_Anew" #this name will show on the ArcGIS online
# optional
##########
out_FeatureDataset= r"Building_A"
GDBfolder_name = r"Automation.gdb" #default
includeDate = False
BIMpublication.CreateBSLpackage(workSpaceEnv, GDBfolder_name , \
out_FeatureDataset, spatial_reference , Rvt_directory, BSL_name,\
nameOfBuildingL , includeDate )
# Publish Building scene layer function
# Required parameters
##########
itemID_BSLp = None
itemID_Hosted = None
# overwrite parameter is importatnt to be set on **True** ##Only change if you know what you are doing##
dictOfPackageLayer = {"overwrite" : True}
DirectoryTo_SLPK = None
BIMpublication.publishBSLfunction(itemID_BSLp, itemID_Hosted, dictOfPackageLayer, DirectoryTo_SLPK)