Link Revit file from Autodesk Docs

Link Revit file from Autodesk Docs

steven.williams.as
Enthusiast Enthusiast
470 Views
2 Replies
Message 1 of 3

Link Revit file from Autodesk Docs

steven.williams.as
Enthusiast
Enthusiast

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):

stevenwilliamsas_1-1661456257434.png

I tried using Forge to get the modelGuid/projectGuid, but no such attributes exist:

stevenwilliamsas_2-1661456399611.png

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()

 

 

2022-08-25 12.26.57 Revit_rF3yF1Kx7Z.png

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:

Autodesk Help: Revit Links 

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: Error while linking Cloud Revit file using ExternalResourceReference - The ExternalRe... 

StackOverflow: Is it possible to load new Cloud (BIM 360) links in a Revit model either through the ... 

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 

0 Likes
471 Views
2 Replies
Replies (2)
Message 2 of 3

jeremy_tammik
Autodesk
Autodesk

Wow. That is the most impressive list of links to prior research that I have ever seen. Very sorry that the answer appears to be so elusive. Have you seen this little solution?

  

https://forums.autodesk.com/t5/revit-api-forum/opening-a-cloud-model-with-revit-api/m-p/10991029

 

I guess the real question is short and simple: why do the files you want to link lack the modelGuid and projectGuid attributes? Do you agree? 

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 3 of 3

steven.williams.as
Enthusiast
Enthusiast

I wish it were that simple. I can find no way to retrieve the modelGuid and projectGuid from the Revit files on Autodesk Docs. That was the second screenshot in the post -- data.attributes.extension does not contain that information. In fact, there is no Guid attribute anywhere in the Forge .rvt file metadata that I can find. It works for models that are saved for collaboration, but not for normal Revit files that have been simply uploaded to a folder.

0 Likes