BIM 360 Document Management Project Id of Revit cloud model?

BIM 360 Document Management Project Id of Revit cloud model?

kevinaugustino
Contributor Contributor
10,971 Views
6 Replies
Message 1 of 7

BIM 360 Document Management Project Id of Revit cloud model?

kevinaugustino
Contributor
Contributor

How can I retrieve the BIM 360 Document Management Project Id of the active Revit model? I'm aware of Document.GetCloudModelPath().GetProjectGUID() but this seems to be a C4R Project Id. I need the Document Management Id to interface with the Forge BIM 360 (And Data Management) APIs (https://forge.autodesk.com/en/docs/bim360/v1/reference/http/).

 

So far I've found that the Document Management file has an attribute that matches the C4R Project Guid: attributes.extension.data.projectGuid

So I need to find the Docs project that contains a file such that attributes.extension.data.projectGuid=<ActiveRevitDocument>.GetCloudModelPath().GetProjectGUID(). But surely there's a better approach than doing a folder search (https://forge.autodesk.com/en/docs/data/v2/reference/http/projects-project_id-folders-folder_id-sear... using a filter "filter[attributes.extension.data.projectGuid]=<ValueFromCloudModelPath>") on every Docs Project that my Forge App has access to?

0 Likes
10,972 Views
6 Replies
Replies (6)
Message 2 of 7

jeremytammik
Autodesk
Autodesk

I asked the development team for you whether they can suggest a better way.

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 3 of 7

jeremytammik
Autodesk
Autodesk

The development team are discussing the implementation of a directly method to retrieve the BIM 360 project id of the document via a property such as Document.ProjectId as we speak. It will hopefully be available in a future release of Revit. Thank you for your patience! Meanwhile, the convoluted approach you describe sounds significantly better than nothing to me, so well done finding a way through the maze.

  



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 4 of 7

kevinaugustino
Contributor
Contributor

Thank you Jeremy!

 

For anyone else who runs into this same need, here's some of my other findings:

 

Document.PathName seems to be a string in this form when opening a cloud model:

BIM 360://<DocsProjectName>/<ModelName>.rvt

 

So another option is to try parsing Document.PathName to get the Document Management Project name:

string regexPattern = @"^BIM 360:\/\/(?<ProjectName>.*)\/(?<ModelName>.*)$";
if (Regex.IsMatch(doc.PathName, regexPattern))
{
    Match match = Regex.Match(doc.PathName, regexPattern);
    string projectName = match.Groups["ProjectName"].Value;
}

Then look for a project with that name by iterating each hub returned from https://forge.autodesk.com/en/docs/data/v2/reference/http/hubs-GET/ , and on each one, try to get a project using a name filter (https://forge.autodesk.com/en/docs/data/v2/reference/http/hubs-hub_id-projects-GET/  (using a filter such as string.format("?filter[attributes.name]={0}", HttpUtility.UrlEncode(projectName)) )

 

If this project name isn't unique, then this approach might not get the correct one. But additional processing can be applied to use a folder search looking for attributes.extension.data.projectGuid=<ActiveRevitDocument>.GetCloudModelPath().GetProjectGUID() . So at least this way, the folder search is only done on potential matches, rather than every single project.

 

If the Document Management project name changes, then Document.PathName won't refresh to the new project name until you re-save the model. So as a fallback, if I still haven't found the project Id, I resort to the folder search on every project regardless of name.

 

Not ideal, but hopefully a direct method will be added to the Revit API in the future!

0 Likes
Message 5 of 7

sedober
Participant
Participant

Hey Kevin,

 

Jumping in a little late on this but I've been working on something similar and might have a useful suggestion. If you have any links within your model that are on the same BIM360 Docs project, then one method you could try leveraging to get the Document Management Project Id is calling GetReferenceInformation() on the ExternalResourceReference for the link. That appears to return the following fields for BIM360 Revit links:

'ForgeDmItemUrn' : contains the Forge Datamanagement Item ID,

'ForgeDmProjectId' : contains the Forge Datamanagement Project ID,

'LinkedModelModelId' : contains the Model GUID,

'LinkedModelProjectId' : contains the Project GUID

 

I think the ForgeDmProjectId is what you're after. Unfortunately I haven't been able to find a way to get this directly on the Active Document itself through the Revit API but it's doable if there are links to query. Here's a code sample to get this through the Revit Python Shell:

 

from Autodesk.Revit.DB import *;
uidoc = __revit__.ActiveUIDocument;
doc = __revit__.ActiveUIDocument.Document;
linkName = "Link.rvt";

bip = BuiltInParameter.SYMBOL_NAME_PARAM;
provider = ParameterValueProvider(ElementId(bip));
evaluator = FilterStringEquals();
rule = FilterStringRule(provider, evaluator, linkName, True);
filter = ElementParameterFilter(rule);

link = FilteredElementCollector(doc).OfClass(RevitLinkType).WherePasses(filter).ToElements()[0];
print link.get_Parameter(BuiltInParameter.SYMBOL_NAME_PARAM).AsString();
extRes = link.GetExternalResourceReference(ExternalResourceTypes.BuiltInExternalResourceTypes.RevitLink);
print extRes.GetReferenceInformation();

 

Message 6 of 7

richard.schmitt.sg
Contributor
Contributor

@jeremytammik any update on the ProjectId property you mentioned? would be very useful

0 Likes
Message 7 of 7

kevinaugustino
Contributor
Contributor

Yes, they added new API calls in Revit 2022, new instance methods in Autodesk.Revit.DB.Document class.

 

Document.GetProjectId() is what we needed but they also added these useful methods:

 

Document.GetHubId() (The Data Management Hub Id which can be converted to a BIM360/ACC Account Id by removing the 'b.' prefix)

Document.GetCloudFolderId() (the Document Management Folder Id that the model resides in)

Document.GetCloudModelUrn() (the Document Management Item Id of the model)