You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

如何在Autodesk Forge Viewer中加载带链接文件的Revit文档?

Got it, let's tackle how to load Revit files with linked documents in your Forge Viewer setup. Here's a step-by-step breakdown that aligns with the core ideas from that older tutorial, adapted for modern Viewer implementations:

Loading Revit Files with Linked Documents in Forge Viewer

1. First, Make Sure Your Model Derivative Job Processes Linked Files

When submitting your Revit file for translation via the Model Derivative API, you need to explicitly tell the service to include linked documents. If you're handling this in your ASP.NET backend, update your translation payload to enable linked file processing:

var jobPayload = new
{
  input = new
  {
    urn = "your-main-revit-file-urn"
  },
  output = new
  {
    formats = new[]
    {
      new
      {
        type = "svf",
        views = new[] { "2d", "3d" },
        advanced = new { includeLinkedFiles = true } // This is the key flag
      }
    }
  }
};

The older tutorial used a references parameter, but modern API versions use includeLinkedFiles to trigger processing of all linked Revit files attached to your main model.

2. Fetch the Full Model Manifest to Confirm Linked Files Are Ready

Before loading the main model, fetch its manifest to verify all linked files have been successfully translated. You can do this either in your ASP.NET backend or directly in the frontend:

// Frontend example: Fetch manifest to check linked derivatives
async function getModelManifest(urn) {
  const response = await fetch(`/api/forge/modelderivative/manifest/${urn}`, {
    headers: { 'Authorization': `Bearer ${accessToken}` }
  });
  return response.json();
}

Loop through the derivatives array in the manifest to find entries marked as reference—these are your linked files. Note down their urn values, you'll need them for loading.

3. Load the Main Model + Linked Files Together in the Viewer

Use the loadDocumentNode method and pass in options that include your linked files. This replaces the older setReferences method from the legacy tutorial:

// Load the main Revit document and its links
Autodesk.Viewing.Document.load(
  `urn:${mainModelUrn}`,
  async (mainDoc) => {
    // Get the default viewable from the main document
    const mainViewables = mainDoc.getRoot().getDefaultGeometry();
    
    // Define your linked files (pulled from the manifest earlier)
    const linkedReferences = [
      {
        urn: `urn:${firstLinkedFileUrn}`,
        // Optional: Add transform if you need to reposition the linked model
        // transform: new THREE.Matrix4().makeTranslation(10, 0, 0)
      },
      {
        urn: `urn:${secondLinkedFileUrn}`
      }
    ];

    // Load the main model with links included
    const loadOptions = {
      sharedPropertyDbPath: mainDoc.getPropertyDbPath(), // Share property data across models
      references: linkedReferences
    };

    viewer.loadDocumentNode(mainDoc, mainViewables, loadOptions);
  },
  (error) => {
    console.error('Failed to load main document:', error);
  }
);

If your linked files were properly included in the translation job, the Viewer will automatically resolve them, but explicitly defining references ensures reliability for complex link structures.

4. Manage Linked Model Visibility & Interaction (Optional)

Once loaded, you can control linked models using Viewer APIs:

// Get all external linked models
const linkedModels = viewer.impl.modelQueue().getModels().filter(model => model.isExternal);

// Hide the first linked model
if (linkedModels.length > 0) {
  viewer.hide(linkedModels[0].getRootId());
}

Quick Notes to Avoid Issues

  • Ensure your access token has viewables:read permission for all linked file URNs, not just the main model.
  • For nested Revit links, includeLinkedFiles defaults to recursive processing, so all levels of links will be translated.
  • If you're using the older SVF1 format, the process is nearly identical—just omit sharedPropertyDbPath from the load options.

内容的提问来源于stack exchange,提问作者ahmed.ramadan

火山引擎 最新活动