Python - Automated creation of ACC cloud links

This code returns Project and Model GUIDs of given Documents given as list.

import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Structure import *

def get_cloud_model_info(doc):
    try:
        path = doc.GetCloudModelPath()
        mpat = ModelPathUtils.ConvertModelPathToUserVisiblePath(path)
        mguid = path.GetModelGUID()
        pguid = path.GetProjectGUID()
        return (path, mpat, mguid, pguid)
    except:
        # Skip if the document is not a cloud model
        return None

docs = IN[0]  # assuming this is a list of documents
output = [get_cloud_model_info(doc) for doc in docs if doc]

OUT = output

This code creates in current model links to a given ACC models.
Inputs -Project GUIDs- and list of -Model GUIDs-
Current project has to be a model on ACC within the same project that links will be.

import clr
import System
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference('RevitServices')
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument
input_string = 'EMEA'
project_guid = System.Guid(IN[0])
model_guids = [System.Guid(guid) for guid in IN[1]]
linkOptions = RevitLinkOptions(False)

revitLinkInstances = []
try:
    TransactionManager.Instance.EnsureInTransaction(doc)
    for model_guid in model_guids:
        cloudPath = ModelPathUtils.ConvertCloudGUIDsToCloudPath(input_string, project_guid, model_guid)
        mpat = ModelPathUtils.ConvertModelPathToUserVisiblePath(cloudPath)
        revitLinkType = RevitLinkType.Create(doc, cloudPath, linkOptions)
        revitLinkInstance = RevitLinkInstance.Create(doc, revitLinkType.ElementId)
        revitLinkInstances.append(revitLinkInstance)
    TransactionManager.Instance.TransactionTaskDone()
except Exception as e:
    erro = f"An error occurred: {str(e)}"
    revitLinkInstances.append(erro)
    
OUT = revitLinkInstances


Hi @Ftad

thanks for this- very useful. A couple of questions:

  • You can add a description attribute to models in ACC, but you can’t see it in Revit. I think it is more of a design flaw in Revit- the ACC description should really come up as a parameter of a linked model. I was wondering if your code could be modified to include this, or other attributes that could be fed into a linked models parameters ? For example, listing the last modified date could be handy, rather than backtracking through ACC.
    For example- like this

    (doesn’t work)
    I’ve had a look in the ACC docs- the closest I can see is this Fetch Description Attribute of File Item of ACC and BIM360 | Autodesk Platform Services

  • I’ve noticed that the data returned shows the original name of any models if they have been renamed, or the project if it has been renamed.
    ACC obviously keeps the IDs etc the same for any renamed models- just the display name is changed.
    So to show the current model name- similar to the above, perhaps your code could show ‘displayname’ or maybe just easier to use the link name which always seems to match what is shown in Revit ??

Andrew

had to say it, ur profile pic is seriously cool.

2 Likes