Is it possible to load new Cloud (BIM 360) links in a Revit model either through the Revit API or FORGE API? - autodesk-forge

I have a two-part WPF App and Revit Addin that runs a series of routines to create and activate a new BIM 360 project via the FORGE BIM 360 API, launches Revit and creates and sets up a collection of Revit models from a "seed" Revit model. The primary requirement is to have zero user interaction in this process: to be fully automated.
Given that background, I am having trouble linking the newly saved BIM 360 models to one-another. I have the option to do this either in the Revit Addin with Revit API hooks (preferred) or through the manager WPF App with FORGE API REST calls after the models are created.
Is either one possible?
I have successfully linked with the cached local models as described here and here. However, this does not meet the requirement fully, since when any other user (besides the automation machine user) opens the model the links are Not Found.
Screenshot of links Not Found.
Current "sort-of-working" code:
var wId = GetWorksetId(doc, w);
if (wId != null)
{
string localPath = settings.CloudModels.Where(x => x.ModelName == _linkModelNames[i]).Select(x => x.LocalFilePath).First();
ModelPath path = ModelPathUtils.ConvertUserVisiblePathToModelPath(localPath);
using (var options = new RevitLinkOptions(true))
{
using (var t = new Transaction(doc, w))
{
t.Start();
doc.GetWorksetTable().SetActiveWorksetId(wId);
using (var result = RevitLinkType.Create(doc, path, options))
{
_ = RevitLinkInstance.Create(doc, result.ElementId);
}
t.Commit();
linkPlaced++;
}
}
}
I was able to get the correct ModelPath via the Revit API thanks to this helpful tip. I can save this value in my Addin, close the model, and access the property later after opening a different model (saved in the CloudModels class referenced in the linq statement in the code snippet above). Unfortunately for me RevitLinkType.Create() that takes a ModelPath does not accept the cloud path, so I may have hit another dead end. Unless it is possible with an ExternalResourceReference. Has anyone tried this option? If so, how do you assemble a Revit ExternalResourceReference? I am not familiar with this process, and looking over this course from AU 2017, I don't see that it necessarily applies to BIM 360 cloud models. A BIM 360 cloud example would be very helpful if this is possible.
Alternate strategy: I do not see any reference to loading links in the FORGE Data Management API or other FORGE APIs. If I have somehow missed it, please share a link.
Any help would be very much appreciated!!
EDIT: I have since found these two (1) (2) similar questions that, at least for my purposes, were not answered satisfactorily. Any updates I should be aware of?

As of now (Jan 2020), unfortunately, we do not have a Link API for cloud models. It is on the roadmap.

Revit API 2022 docs mention that
The methods:
RevitLinkType.Create(Document, ModelPath, RevitLinkOptions)
RevitLinkType.LoadFrom(ModelPath, WorksetConfiguration)
have been enhanced to support creation of new cloud model Revit links.
You may use ModelPathUtils.ConvertCloudGUIDsToCloudPath() to
create a cloud path to use as an argument to these methods.
Additional Resource:
This Youtube Video showcases an example and its respective Github repo.

For Revit 2021 and below, you can use ExternalResourceReference() as a workaround, but I've noticed that this is not always reliable.
Its also mentioned in the documentation of InSessionPath property to not rely on this property:
Do not rely on this path (InSessionPath ) to look up an ExternalResourceReference, as the path is neither unique nor stable. It isn't unique because multiple servers might use the same server name and display name format. It isn't stable because some servers allow renaming, and because a server might change its name at some point.
Below is the code to do that:
var linkCloudPath = doc.GetCloudModelPath(); // the cloudpath of a BIM360 model
Guid linkedmodelguid = linkCloudPath.GetModelGUID();
Guid linkedprojectguid = linkCloudPath.GetProjectGUID();
Dictionary<string, string> Dictionary_ExternalResource = new Dictionary<string, string>(){
{"LinkedModelModelId", modelGuid.ToString()},
{"LinkedModelProjectId", projGuid.ToString()}
};
Dictionary<string, Guid> servers = new Dictionary<string, Guid>();
foreach (var service in ExternalServiceRegistry.GetServices())
{
if (service.Name == "External Resource Service")
{
IList<Guid> server_ids = service.GetRegisteredServerIds();
foreach (var server_id in server_ids)
{
servers.Add(service.GetServer(server_id).GetName(), server_id);
}
}
}
Guid BIM360ServerID = servers["BIM 360"];
ExternalResourceReference ERS = new ExternalResourceReference(BIM360ServerID, Dictionary_ExternalResource, "", "");
RevitLinkOptions options = new RevitLinkOptions(false);
LinkLoadResult result = RevitLinkType.Create(gcdoc, ERS, options);
RevitLinkInstance.Create(gcdoc, result.ElementId);
Please note that this seems to be working fine in Revit 2020, but not in Revit 2021.

I believe it is possible to create links to the Cloud Models in Revit 2019 or higher (with ModelPathUtils.ConvertCloudGUIDsToCloudPath()). You'll need the ProjectGUID and ModelGUID to make the cloud model path.
Regarding the ExternalResource approach, that also works - but it's super messy - you can read the properties associated with existing BIM360 links and you'll see how an ExternalResource is defined for BIM360 links.
Finally - as of today, the Forge Design Automation for Revit approach would not work for you at all:
1. Not possible to open a live cloud workshared model (only published/uploaded models).
2. No network access while you're running in a Design Automation for Revit session.
Good luck...
-Matt

Related

Created DirectShape is not extracted through forge

I generated (in debug mode an addin) DirectShape as a Volume of a Room as in:
https://github.com/jeremytammik/RoomVolumeDirectShape
Rooms are generated and REVIT file is saved correctly, then I send it to FORGE for processing and I extract Model View Metadata Properties (mvmp) and the OBJ.
The issue is that MVMP does not contain any information of recently generated room volumes, the object is:
DirectShape ds = DirectShape.CreateElement(doc, _id_category_for_direct_shape);
ds.ApplicationId = id_addin;
ds.ApplicationDataId = r.UniqueId;
ds.SetShape(geo.ToList<GeometryObject>());
ds.get_Parameter(_bip_properties).Set(json);
ds.Name = "Room_Max_is_an_okayish_dev_" + r.Name;
The question here is: how should I modify it so it will be included in the extraction mvmp.json?
I suspect I need to tag it somehow or add it to some sort of collection.
Please help.
Thank you in advance.
In Revit, you can define which views are to be included in the Forge translation process.
Ensure that you see your direct shapes in at least one of your Revit views, and that this view is earmarked for translation to Forge.

Revit Design Automation: Possible to Set IFC Export Setting?

I noticed that Model Derivatives are able to translate Revit to IFC using a specified Export Setting Name. Is it possible to do the same in Design Automation? The Autodesk exporter (Autodesk.IFC.Export.UI) is able to utilize saved export settings, but it can not be used in Design Automation because it depends on RevitAPIUI. Currently, I've tried snipping parts of the source code and putting it into my add-in, but I wonder if there is an easier way to do this.
Update:
Migrated Revit add-in for Revit DA: https://github.com/yiskang/forge-revit-ifc-exporter-appbundle
==========
Unfortunately, it's not builtin in Revit DA I'm afraid, since they come from Autodesk/revit-ifc.
But you may port IFCExportConfigurationsMap.cs, IFCExportConfiguration.cs and Enums to your own Revit addin.
Usage example:
var configurationsMap = new IFCExportConfigurationsMap();
//configurationsMap.Add(IFCExportConfiguration.GetInSession());
configurationsMap.AddBuiltInConfigurations();
configurationsMap.AddSavedConfigurations();
var selectedConfig = configurationsMap["IFC2x3 Coordination View 2.0"];
var exportOptions = new IFCExportOptions();
ElementId activeViewId = document.ActiveView.Id;
selectedConfig.ActiveViewId = selectedConfig.UseActiveViewGeometry ? activeViewId.IntegerValue : -1;
selectedConfig.UpdateOptions(exportOptions, activeViewId);
bool result = document.Export(path, fileName, exportOptions);
refs:
https://github.com/Autodesk/revit-ifc/blob/9a6fc912fb8510647f9d2bcc0d57b0451a2194b6/Source/IFCExporterUIOverride/IFCCommandOverrideApplication.cs#L184
https://github.com/Autodesk/revit-ifc/blob/9a6fc912fb8510647f9d2bcc0d57b0451a2194b6/Source/IFCExporterUIOverride/IFCCommandOverrideApplication.cs#L261

Upload Revit model files to BIM360 via API and keep them linked

I have two Revit model files, A and B, where B is linked into A. I want to upload the files to BIM360 Docs via the Autodesk.Forge API and keep them linked, so I can see the combined model in the Forge Model viewer when I subsequently view model A.
I have the two files in a zip file, but from what I understand, I shouldn't upload the zip file, but rather upload A and B separately, then create a relationship between them.
I can upload the files without problems, and I've then tried to link them via this code (using the NON-encoded version ids for A and B):
public async Task SetLinkedFileRelationship(string projectId, string versionId, string linkedVersionId)
{
BaseAttributesExtensionObject baseAttribute = new BaseAttributesExtensionObject("auxiliary:autodesk.core:Attachment", "1.0");
CreateRefDataMeta meta = new CreateRefDataMeta(baseAttribute);
CreateRefData createRefData = new CreateRefData(CreateRefData.TypeEnum.Versions, linkedVersionId, meta);
CreateRef createRef = new CreateRef(new JsonApiVersionJsonapi(JsonApiVersionJsonapi.VersionEnum._0), createRefData);
VersionsApi versionsApi = new VersionsApi { Configuration = { AccessToken = _token.AccessToken } };
await versionsApi.PostVersionRelationshipsRefAsync(projectId, versionId, createRef);
}
...which produces this response:
status: 400
code: FUNCTION_NOT_SUPPORTED
detail: BIM360 currently does not support the creation of refs.
So apparently I can't create the link between A and B like this. Is there another way to accomplish what I want, or is this currently just not possible in BIM360? I know you can do it via the BIM360 Docs web page (using the Upload file -> Linked Files button), but is it possible when I upload the model files via the API? If so, what is the recipe?
Please keep in mind that my question is for uploading to BIM360 Docs - using the Autodesk.Forge API (v2). I'm aware of this post: BIM360 Docs: Setting up external references between files (Upload Linked Files), but that is targeted at manually composing requests. I'd like to be able to use the v2 API.
I believe this post should help https://forge.autodesk.com/blog/bim360-docs-setting-external-references-between-files-upload-linked-files.

Is there extension to show the models on a level?

I'd like to make a function to show models on a level which someone selected like a function that we can see in BIM 360 docs.
level selection in BIM 360 docs
Is there such kind of extension?
Try the Autodesk.AEC.LevelsExtension extension - so long as the model comes with the required AEC data about existing floors:
viewer.addEventListener(Autodesk.Viewing.OBJECT_TREE_CREATED_EVENT/Autodesk.Viewing.GEOMETRY_LOADED_EVENT , //wait till design data is loaded
viewer.loadExtension('Autodesk.AEC.LevelsExtension')
)
You can inspect whether your model contains the necessary data using model.getAecModelData()

Trying to get Google Drive to work with PCL Xamarin Forms application

I’m using Xamarin Forms to do some cross platform applications and I’d like to offer DropBox and GoogleDrive as places where users can do backups, cross platform data sharing and the like. I was able to get DropBox working without doing platform specific shenanagins just fine, but Google Drive is really giving me fits. I have my app setup properly with Google and have tested it with a regular CLI .NET application using their examples that read the JSON file off the drive and create a temporary credentials file – all fine and well but getting that to fly without access to the file system is proving elusive and I can’t find any examples on how to go about it.
I’m currently just using Auth0 as a gateway to allow users to provide creds/access to my app for their account which works dandy, the proper scope items are requested (I’m just using read only file access for testing) – I get an bearer token and refresh token from them – however when trying to actually use that data and just do a simple file listing, I get a 400 bad request error.
I’m sure this must be possible but I can’t find any examples anywhere that deviate from the slightest of using the JSON file downloaded from Google and creating a credentials file – surely you can create an instance of the DriveService object armed with only the bearer token...
Anyway – here’s a chunk of test code I’m trying to get the driveService object configured – if anyone has done this or has suggestions as to what to try here I’d very much appreciate your thoughts.
public bool AuthenticationTest(string pBearerToken)
{
try
{
var oInit = new BaseClientService.Initializer
{
ApplicationName = "MyApp",
ApiKey = pBearerToken,
};
_googleDrive = new DriveService(oInit);
FilesResource.ListRequest listRequest = _googleDrive.Files.List();
listRequest.PageSize = 10;
listRequest.Fields = "nextPageToken, files(id, name)";
//All is well till this call to list the files…
IList<Google.Apis.Drive.v3.Data.File> files = listRequest.Execute().Files;
foreach (var file in files)
{
Debug. WriteLine(file.Name);
}
}
catch (Exception ex)
{
RaiseError(ex);
}
}