简体   繁体   English

获取 Revit Workshared 云模型作为 C# Autodesk.Revit.DB 文档类

[英]Get Revit Workshared cloud model as C# Autodesk.Revit.DB Document class

I have a Revit plug-in, I want it to do some operations on a workshared cloud model.我有一个 Revit 插件,我希望它对工作共享云模型执行一些操作。

I can't figure out how to get the Revit model as a Document class (Autodesk.Revit.DB) which is stored live on BIM360 cloud, not a local copy, nor downloaded copy.我不知道如何将 Revit 模型作为文档类 (Autodesk.Revit.DB) 获取,它实时存储在 BIM360 云上,而不是本地副本,也不是下载的副本。

Seems like I have to use different API's and there are multiple steps to this although I was expecting something relatively simpler, I quickly realised this actually may have multiple steps which I honestly can't figure out.似乎我必须使用不同的 API,并且有多个步骤,虽然我期待的是相对简单的东西,但我很快意识到这实际上可能有多个步骤,老实说我无法弄清楚。

Is there a working relevant code example on git hub for this? git hub 上是否有与此相关的工作代码示例?

Edit: I was able to find the below code but it doesn't compile because ForgeClient and OSSObjectsApi doesn't exist in the latest forge sdk package, how can I fix that?编辑:我能够找到下面的代码,但它无法编译,因为最新的 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;
        }
    }
}

To open a live Revit Could Model (RCM), please use the ModelPathUtils.ConvertCloudGUIDsToCloudPath() to convert project and model guid into a ModelPath .要打开实时 Revit 模型 (RCM),请使用ModelPathUtils.ConvertCloudGUIDsToCloudPath()将项目和模型 guid 转换为ModelPath You can then use this ModelPath to open the document using Application.OpenDocumentFile() method.然后,您可以使用此ModelPath通过Application.OpenDocumentFile()方法打开文档。

Also read the sections Getting the CloudPath for a Model and SaveAsCloudModel Information from the Web Browser in the link on how to find the account, project and model guids of the model you are interested in.另请阅读链接中的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());

This code will work in a desktop addin as long as a valid user is logged in and that user has access to the input model.只要有效用户登录并且该用户有权访问输入模型,此代码就可以在桌面插件中运行。 While you have not explicitly mentioned you need this to work on Design Automation for Revit, you have added the tag #autodesk-designautomation to your question.虽然您没有明确提到您需要这个来处理 Revit 的设计自动化,但您已将标签 #autodesk-designautomation 添加到您的问题中。 The good news is the same code above should work for Design Automation addin (app bundle), but there is an extra step on how to provide user context to the design automation job.好消息是上面的相同代码应该适用于设计自动化插件(应用程序包),但是关于如何为设计自动化工作提供用户上下文还有一个额外的步骤。 Please refer to the blog post and github sample for Design Automation for RCM.请参阅 RCM 设计自动化的博客文章github 示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何确定已发布的工作共享 Revit model 的语言集? - How to determine the language set for a published workshared Revit model? 放大到Autodesk forge中的特定Revit模型对象 - Zoom to a specific Revit model object in Autodesk forge 是否可以使用Forge Model Derivative API从非Autodesk云存储服务转换(Revit)模型? - Is it possible to translate (Revit) models from non-Autodesk cloud storage services using Forge Model Derivative API? Autodesk Revit 装配体 - Autodesk Revit Assembly 是否有用于从Revit模型中提取数据的云API? - Is there a cloud API to extract data from a Revit model? 使用 C# .NET HTTPClient 在 Node JS 服务器上通过 Multer 将 Revit 文件上传到 Autodesk Forge OSS - Uploading a Revit file to Autodesk Forge OSS by Multer on a Node JS server with C# .NET HTTPClient 将Revit文件导入到Forge中时,Revit参数将被重命名。 - Revit parameters are getting renamed when a Revit file is being imported into Forge autodesk-model-derivative Autodesk Forge-模型衍生API:Revit到.obj(基本) - Autodesk Forge - Model Derivative API: Revit to .obj (Basics) Autodesk Forge 下载 object,但无法判断它是 Revit model 还是 zip 文件 - Autodesk Forge download object, but cannot tell if it is a Revit model or zip file Autodesk Model 衍生产品 API 不检索所有 Revit 数据 - Autodesk Model Derivative API does not retrive all Revit data
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM