Initiate BIM360 Docs collaboration programmatically - autodesk-forge

In order to upgrade to the current version of Revit, we have to migrate our files from from BIM360 Teams to BIM360 Docs. Since we have hundreds of documents, I am looking to automate this process as much as possible.
The forge API allows me to download all Revit files from BIM360 Teams. I am also able to upgrade them all to Revit 2019, using either the Revit API or a third party app such as this Bulk File Upgrader`.
Using the Forge BIM360 API, I am able to create new projects programmatically, and upload the files and folders from the Team Drive. The step that I am having difficulty accomplishing in an automated fashion is to initiate collaboration for the upgraded Revit 2019 files. Is there a way that this can be accomplished with either the Revit API or the Forge API? Or is there another way that allows me to automatically accomplish the migration between these two Autodesk Cloud Collaboration solutions?
I came across this tutorial on publishing models, which suggests that one needs to manually initiate collaboration for each Revit file through the Revit UI. I hope to find an alternative solution to this suggestion.
Thank you!

My colleague Eason Kang 康益昇 confirmed that you can use the steps provided in my previous answer to achieve this as follows:
Revit 2019.2 and future releases include support for the "Single user workflow", the non-workshared cloud model. At the same time, they expose the API to initiate the non-workshared cloud model and convert the non-workshared cloud model to a workshared cloud model (C4R).
You can use the single user APIs to workaround the cases you mentioned as follows:
Save the downloaded files and non-workshared files to your local file system.
Initiate non-workshared cloud model through the API call to Document.SaveAsCloudModel.
Convert it to a C4R model via the API Document.EnableCloudWorksharing.
Here is his report, including the solution to a credentials issue on the way:
Question: I would like to save a local RVT to my BIM360 account – with Design Collaboration service activated – using the Revit 2020 API, but Revit always throws an exception saying that I do not have the access rights. I have a valid C4R license and able to open C4R models from the folder id I passed to the API with the Revit UI. What is missing?
Code:
doc.SaveAsCloudModel(
"urn:adsk.wipprod:fs.folder:co.8rtX03jDQXKnssA1FfrEXw",
doc.Title);
Exception:
Autodesk.Revit.Exceptions.RevitServerUnauthorizedException: You do not have cloud model entitlement to access this resource in cloud
Answer: You need to have the 'Cloud Models for Revit' entitlement set up in manage.autodesk.com.
Response: Thank you for clarifying. I confused the 'Cloud Models for Revit' with the C4R, and I didn't have the 'Cloud Models for Revit' entitlement set up in my manage.autodesk.com.
Answer: 'Cloud Models for Revit' is a new service provided since Revit 2019.2. It is part of the Revit and Revit LT subscription.
Btw, the major difference to the C4R models is thaT only one user at a time can work on the model created by this method.
Response: Great!
I set up my Revit Subscription as required, followed the steps shared above by Jeremy and confirmed that it works!
You can achieve the goal through the Revit API using the following steps:
Initiate a non-workshared cloud model through the API call to Document.SaveAsCloudModel.
Convert it to a C4R model via the API Document.EnableCloudWorksharing.
Here is my test code implementing this:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
namespace adsk.c4r
{
[Transaction(TransactionMode.Manual)]
public class Command : IExternalCommand
{
public Result Execute(
ExternalCommandData commandData,
ref string message,
ElementSet elements)
{
UIApplication uiapp = commandData.Application;
UIDocument uidoc = uiapp.ActiveUIDocument;
Application app = uiapp.Application;
string template = app.DefaultProjectTemplate;
string filename = #"D:\DevZone\ADN\t5021\revit_api_c4r_test_6.rvt";
string name = System.IO.Path.GetFileName(filename);
Document doc = app.NewProjectDocument(template);
doc.SaveAs(filename);
try
{
doc.SaveAsCloudModel(
"urn:adsk.wipprod:fs.folder:co.aCd1tMmrTxucmJcmtYTLBQ",
name);
var cloudPath = doc.GetCloudModelPath();
if(doc.CanEnableCloudWorksharing())
{
doc.EnableCloudWorksharing();
}
TaskDialog.Show("Revit",
string.Format("{0} is a C4R model now", name));
doc.Close();
uiapp.OpenAndActivateDocument(cloudPath, new OpenOptions(), false);
}
catch(Exception ex)
{
System.Diagnostics.Trace.WriteLine(ex.Message);
return Result.Cancelled;
}
return Result.Succeeded;
}
}
}

Sorry for the delay answering this.
This issue sounds similar to the one raised in the Revit API discussion forum and escalated to the ADN case 14906646 Old topic brought back - changing link paths to Cloud paths.
We have raised the question with the Revit, C4R, Forge and Desktop Connector development teams, causing lively discussion with no clear answer yet in sight.
We are researching as hard and fast as possible and will provide a more conclusive answer asap.

The development team are still discussing this issue. Meanwhile, they also said:
This request is recorded in the development issue REVIT-140793.
There may be a workaround to achieve what you need.
Revit 2019.2 and future releases include support for the "Single user workflow" -- that is the non-workshared cloud model. At the same time, they expose the API to initiate the non-workshared cloud model and convert the non-workshared cloud model to a workshared cloud model (C4R).
So, I think you can use the single user APIs to workaround the cases you mentioned as follows:
Save the downloaded files and non-workshared files (local files).
Initiate non-workshared cloud model through the API call to Document.SaveAsCloudModel.
Convert it to a C4R model via the API Document.EnableCloudWorksharing.

Autodesk has also recently published a GitHub repository with a solution for this exact scenario. You can find the video here which talk about this. This basically uses enhanced api calls in Revit 2022 API - RevitLinkType.Create & RevitLinkType.LoadFrom which support cloud model creation and linking.
There's a related question about how to create new cloud models using Revit API.

Related

Save a workshared model as a cloud model to BIM360

Is it possible to save a workshared model to BIM360 as a workshared cloud model using Revit API and/or Forge API ?
I have multiple models that I wish to upload on BIM360, but from what I see the SaveAsCloudModel method that is currently available in Revit 2021 API and described in this post only works with non-workshared models. Is there any other method ?
According to Revit API Docs, this functionality has been added in Revit 2022 API
SaveAsCloudModel() now supports save of a new Revit Cloud Worksharing central model
The method:
Document.SaveAsCloudModel(Guid, Guid, String, String)
has been enhanced to support upload of local workshared file into BIM 360 Design as a Revit Cloud Worksharing central model.
In addition, the exception UnauthenticatedUserException is removed from the documented exceptions for this method.
Additional References
Similar question in Autodesk forum: Initiate cloud collaboration for a workshared model
The SaveAsCloudModel function is available since Revit 2019.2, and you can follow my code snippet shared here to activate the cloud worksharing:
https://thebuildingcoder.typepad.com/blog/2019/11/initiating-bim360-collaboration-and-linking.html
BTW, you need to install the Revit 2019.2 service package before coding.

How to query for TimeLiner data from Forge API?

I used the TimeLiner plugin for Navisworks to create a 4D timeline. I'm now trying to grab this TimeLiner data from the Forge API. When I log into BIM360, I'm able to load a model into the viewer and see all TimeLiner information within a browser. However, I don't see how I can accomplish this with the Forge API. Is there an available API for this? Or is there another way to grab this info?
Unfortunately, the Timeliner properties are not extracted by Forge service (which BIM 360 is running on), and also some other properties. This blog tells in detail:
https://forge.autodesk.com/blog/updates-navisworks-nwd-translation-engine-coming
Currently, we do have an advanced option to override default configurations to tell NWD/NWC translator if it needs to translate Timeliner properties. BUT, this option is about Forge Model Derivative API ONLY.
While in BIM360 Docs UI, there is no any plan to expose options to let users override default configurations when they upload files. So for now, users uploading NWD/NWC files to BIM 360 Docs will lose Timeliner properties. Consequently, you will have to open those files inside Navisworks to view Timeliner data or take advantage of the Navisworks API to extract the data inside Navisworks. We apologize for the inconvenience.
However, we have legged a wish BIMPLT-698 with BIM360 engineering team to evaluate the possibility of adding options for end-user when they upload the model files. You're welcome to track the updates in the future via sending an email quoting this wish id to the Forge support channel.
Note. Triggering your own translation job to override your desired translation configurations via Forge Model Derivative API on files uploaded to BIM360 will charge you for cloud credits. You will have to consider the extra costs if you want to do so, and see here for the pricing: https://forge.autodesk.com/pricing

Use Forge to Access Change Report from BIM 360

Is it possible to use Forge with some BIM 360 API to gain access to the changes in a model from one version to the next?
Unfortunately, there is no API available for doing BIM360 model comparison on Forge currently. However, here are two workarounds you might be interested in:
Compare changes via Forge Viewer: https://forge.autodesk.com/blog/comparing-versions-viewer
Dump changes via Revit Addin, and then integrate its results with Forge.
What you can do though is to leverage Webhook to get notified when a new version is “upserted” to the Data Management API. See docs here:
Official Doc: https://forge.autodesk.com/en/docs/webhooks/v1/tutorials/create-a-hook-data-management/
Sample Code: https://forge.autodesk.com/blog/webhooks-and-bim-360-c

Interconnecting autodesk forge and Vault api

Currently I'm working on a project where i need to use forge viewer and vault APIs
The system i'm developing should get files from vault and display those in the forge viewer.
I couldn't find any guide or references on how to connect both API's to achieve my goal.
Vault and Forge are two different APIs. And currently, as I know, we have not integrate Vault file system with Forge services, which means the Vault files cannot be accessed in the role of users (while some other cloud products support such as BIM 360, Fusion 360, because they are built on Forge services as well)
So, you would need to use Vault API to get the files from Vault, and use Forge web service to upload and translate the file, in order to view the model in the Forge Viewer.
I am not sure if you have played with Vault API or Forge API. These are just some materials which might be useful:
Using the Vault API and View and Data API Together to Download and View
Assemblies
https://www.autodesk.com/autodesk-university/class/Using-Vault-API-and-View- and-Data-API-Together-Download-and-View-Assemblies-2015
This was delivered by our colleague in 2015 Autodesk University. At that time,
the technology of viewing model in the browser is called View and Data. The
basic workflow is similar to current Forge Viewer.
Vault APIs tutorials:
https://www.autodesk.com/developer-network/platform-technologies/vault
which contains the materials how to get started with Vault. As to the specific topics on downloading files, you can refer to the handout in the above AU class
Forge Viewer tutorials
https://forge.autodesk.com/en/docs/viewer/v6/tutorials/
And I also recommend the other step by step tutorial:
http://learnforge.autodesk.io/
Should you have any questions in the process, please feel free to pose the questions with autodesk-forge tag.

Is it possible to translate (Revit) models from non-Autodesk cloud storage services using Forge Model Derivative API?

I just tried some of the Forge boilerplates on Github.
Some examples asked me to login to BIM 360 to fetch some model data. I was wondering if it would be possible to load the (Revit) models from Dropbox, Google Drive or OneDrive, or even upload them from the local storage?
PS: Forge is awesome, kudos to Forge Team!
We have multiple examples that illustrate how to integrate Forge with cloud storage providers under the same github org:model.derivative-nodejs-box.viewer, data.management-nodejs-integration.box, model.derivative-nodejs-google.drive.viewer
The point of using 3-legged API is precisely to let your app access customer data that is already hosted on Autodesk Cloud. If you want use a storage mechanism that is specific to your app, then you need to use 2-legged Object Storage Service, see Create an App-Managed Bucket and Upload a File
In order to fire a translation on a CAD file, you have to upload your data to Autodesk Cloud first, you can then load it from there in the viewer. However you could also download the svf package using the API and then serve those as static resources from your own server. Take a look at this sample for more info: extract.autodesk.io.
Hope that helps