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