Initiate BIM360 Docs collaboration programmatically

☆樱花仙子☆ 提交于 2020-03-05 00:34:13

问题


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!


回答1:


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;
    }
  }
}



回答2:


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.




回答3:


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:

  1. Save the downloaded files and non-workshared files (local files).
  2. Initiate non-workshared cloud model through the API call to Document.SaveAsCloudModel.
  3. Convert it to a C4R model via the API Document.EnableCloudWorksharing.


来源:https://stackoverflow.com/questions/53892870/initiate-bim360-docs-collaboration-programmatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!