Link Revit file from Autodesk Docs
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am trying to replicate the Insert → Link Revit tool. (I am using RevitPythonShell in Revit 2021.) I think I should use ModelPathUtils.ConvertCloudGUIDsToCloudPath(), but the files I want to link have no modelGuid/projectGuid attributes, even though they are on our Construction Cloud platform.
The file is present on docs.b360.autodesk.com (TEST BIM DUCT R20.rvt):
I tried using Forge to get the modelGuid/projectGuid, but no such attributes exist:
I tried using ModelPathUtils.ConvertUserVisiblePathToModelPath() with both the local filesystem path and the Saved Path shown in the Manage Links window from Revit. The local filesystem path creates an Absolute path type:
path_string = 'C:\Users\s.williams\ACCDocs\Alliant Systems\XXX Test Project 2020\Project Files\TEST BIM DUCT R20.rvt'
model_path = ModelPathUtils.ConvertUserVisiblePathToModelPath(path_string)
options = RevitLinkOptions(False)
with Transaction(doc,'Create link') as t:
t.Start()
rlt = RevitLinkType.Create(doc, model_path, options)
t.Commit()
If I use the the Saved Path (which is also ExternalResourceReference.InSessionPath), it throws a file not found exception:
path_string = r'Autodesk Docs://Alliant Systems/XXX Test Project 2020/Project Files/TEST BIM DUCT R20.rvt'
model_path = ModelPathUtils.ConvertUserVisiblePathToModelPath(path_string)
options = RevitLinkOptions(False)
with Transaction(doc,'Create link') as t:
t.Start()
rlt = RevitLinkType.Create(doc, model_path, options)
t.Commit()
Exception : Autodesk.Revit.Exceptions.FileArgumentNotFoundException: There is not a valid Revit file at path's location
Parameter name: path
By the way, you can get the InSessionPath for each linked Revit file like this:
e = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_RvtLinks).OfClass(RevitLinkInstance).ToElements()
t = [doc.GetElement(x.GetTypeId()) for x in e]
r = [x.GetExternalResourceReferences() for x in t]
erefs = [x.Values for x in r]
path_names = [[y.InSessionPath for y in x] for x in erefs]
print path_names
I even tried using the ExternalServer class to explore RevitLink data provided through the Autodesk Docs ExternalService, but it lists no data (probably I am not trying to do it correctly):
# attempt to explore external resource provider data - only works if a Revit file is already linked in your document
e = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_RvtLinks).OfClass(RevitLinkInstance).ToElements()
t = [doc.GetElement(x.GetTypeId()) for x in e]
r = [x.GetExternalResourceReferences() for x in t]
err = [x.Values for x in r]
server_ids = [y.ServerId for x in err for y in x]
ers = [x for x in ExternalService.ExternalServiceRegistry.GetServices() if x.Name == 'External Resource Service'][0]
servers = [ers.GetServer(x) for x in server_ids]
print 'All servers: ' + str([x.GetName() for x in servers])
server = servers[0]
print 'Selected server: ' + server.GetName()
print 'Bases: ' + str(type(server).__bases__)
ert_guid = ExternalResourceTypes.BuiltInExternalResourceTypes.RevitLink.Guid
resource_type = ExternalResourceType(ert_guid)
match_options = ExternalResourceMatchOptions(resource_type)
browse_data = ExternalResourceBrowserData(doc, server.GetServerId(), '/', match_options)
server.SetupBrowserData(browse_data)
print browse_data.FolderPath
print browse_data.GetSubFoldersData()
print browse_data.GetResources()
Related posts that do not seem to answer my question:
Revit API Forum: How to load link from BIM360
Revit API Forum: Open C4R Document Programmatically
Revit Ideas: Revit API to open BIM 360 -- supposedly implemented, but does not work for my use case
browsing model files in the cloud (A360 C4R)
StackOverflow: How to get Project Guid and Model Guid from PathName?
StackOverflow: How to create URN for Revit File from revit plugin or using Forge apis
StackOverflow: How to find cloud Item id of a Revit model?
Revit API Forum: Is it possible to open a BIM 360 model without using Forge?
Revit API Forum: Is it possible to copy and/or open a C4R model without using Forge?
StackOverflow: Autodesk Forge Data Management References API does not list Revit References
Revit API Forum: Revit 2019 - BIM360 - Unable to repath Revit Links from Cloud to Local Drive
What Revit Wants: Batch Repathing Revit Links to BIM 360 Document Management
Forge Community Blog: Accessing BIM 360 Design models on Revit
The Building Coder: Determine Cloud Model Local File Path
The Building Coder: Referenced Files as a Service
The Building Coder: IOpenFromCloudCallback and the DefaultOpenFromCloudCallback Class