![](/img/trans.png)
[英]How to determine the language set for a published workshared Revit model?
[英]Get Revit Workshared cloud model as C# Autodesk.Revit.DB Document class
我有一个 Revit 插件,我希望它对工作共享云模型执行一些操作。
我不知道如何将 Revit 模型作为文档类 (Autodesk.Revit.DB) 获取,它实时存储在 BIM360 云上,而不是本地副本,也不是下载的副本。
似乎我必须使用不同的 API,并且有多个步骤,虽然我期待的是相对简单的东西,但我很快意识到这实际上可能有多个步骤,老实说我无法弄清楚。
git hub 上是否有与此相关的工作代码示例?
编辑:我能够找到下面的代码,但它无法编译,因为最新的 forge sdk 包中不存在 ForgeClient 和 OSSObjectsApi,我该如何解决?
using System;
using System.IO;
using System.Threading.Tasks;
using Autodesk.Forge;
using Autodesk.Forge.Model;
using Autodesk.Forge.Client;
using Newtonsoft.Json.Linq;
namespace BIM360Downloader
{
class Program
{
static void Main(string[] args)
{
// These are the client ID and client secret that you obtained
// when you registered your application on the Forge developer portal.
string clientId = "YOUR_CLIENT_ID";
string clientSecret = "YOUR_CLIENT_SECRET";
// Replace these with the project ID and file ID of the model you want to download.
string projectId = "YOUR_PROJECT_ID";
string fileId = "YOUR_FILE_ID";
// Create a new Forge API client.
ForgeClient client = new ForgeClient(clientId, clientSecret);
// Get the access token for the client.
TwoLeggedApi oauth = new TwoLeggedApi();
dynamic token = oauth.Authenticate(clientId, clientSecret, "client_credentials", new Scope[] { Scope.DataRead });
string accessToken = token.access_token;
// Set the bearer token for the client.
client.Configuration.AccessToken = accessToken;
// Download the model from BIM 360.
MemoryStream modelStream = DownloadModelAsync(client, projectId, fileId).Result;
Console.WriteLine("Successfully downloaded model to memory stream.");
}
static async Task<MemoryStream> DownloadModelAsync(ForgeClient client, string projectId, string fileId)
{
// Set up the request to download the model.
OSSObjectsApi objectsApi = new OSSObjectsApi();
dynamic objectDetails = await objectsApi.GetObjectDetailsAsync(projectId, fileId);
string bucketKey = objectDetails.bucketKey;
// Download the model data.
dynamic data = await objectsApi.GetObjectAsync(bucketKey, fileId);
byte[] modelData = data.Body;
// Create a new MemoryStream object to store the model data.
MemoryStream modelStream = new MemoryStream(modelData);
return modelStream;
}
}
}
要打开实时 Revit 模型 (RCM),请使用ModelPathUtils.ConvertCloudGUIDsToCloudPath()将项目和模型 guid 转换为ModelPath 。 然后,您可以使用此ModelPath
通过Application.OpenDocumentFile()方法打开文档。
另请阅读链接中的SaveAsCloudModel Information from the Web Browser
Getting the CloudPath for a Model
和 SaveAsCloudModel 信息部分,了解如何查找您感兴趣的模型的帐户、项目和模型 guid。
var cloudModelPath = ModelPathUtils.ConvertCloudGUIDsToCloudPath(region, projectGuid, modelGuid);
Document doc = app.OpenDocumentFile(cloudModelPath, new OpenOptions());
只要有效用户登录并且该用户有权访问输入模型,此代码就可以在桌面插件中运行。 虽然您没有明确提到您需要这个来处理 Revit 的设计自动化,但您已将标签 #autodesk-designautomation 添加到您的问题中。 好消息是上面的相同代码应该适用于设计自动化插件(应用程序包),但是关于如何为设计自动化工作提供用户上下文还有一个额外的步骤。 请参阅 RCM 设计自动化的博客文章和github 示例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.