如何检索 Forge Viewer 对象树?

Gre*_*zer 2 autodesk-viewer autodesk-forge

我的目标是根据我在 Revit 中创建的线条向查看器添加新的几何图形,以突出显示房间,就像它们在此处所做的那样链接

但我不知道如何访问这些线路 ID。我知道它们在 revit (element_id) 中是什么,但不知道它们如何映射为 dbid。

关注此博客文章

我想访问扩展中的 objectTree 来找出答案,但它总是返回为未定义。

var tree;
//old way - viewer is your viewer object - undefined
viewer.getObjectTree(function (objTree) {
 tree = objTree;
});
Run Code Online (Sandbox Code Playgroud)

//2.5 - 未定义

  var instanceTree = viewer.model.getData().instanceTree;
  var rootId = this.rootId = instanceTree.getRootId();
Run Code Online (Sandbox Code Playgroud)

//- 不明确的

  var objectTree = viewer.getObjectTree();
Run Code Online (Sandbox Code Playgroud)

谁能告诉我它是否仍然适用于他们我正在使用 API 的 v2 来将 rvt 转换为 svf 和viewer3D.js 的 2.9

注意如果我调用它,我可以看到 dbid 列表

var model = viewer.impl.model;
var data = model.getData();
var fragId2dbIdArray = data.fragments.fragId2dbId ;
Run Code Online (Sandbox Code Playgroud)

但无法映射回 Revit element_id

Shi*_*Luo 5

As of version 2.9 this is still working. Here's my console: 控制台日志

Here's a couple of things you can try:

  1. Is viewer undefined? Are you in the correct scope when grabbing the viewer?
  2. The document have to be loaded before you can grab the instance tree. When the document is loaded, an event called Autodesk.Viewing.GEOMETRY_LOADED_EVENT will be fired, then you can start manipulating the instance tree.

Simply do this:

viewer.addEventListener(Autodesk.Viewing.GEOMETRY_LOADED_EVENT, function () {
var instanceTree = viewer.model.getData().instanceTree;
});
Run Code Online (Sandbox Code Playgroud)

For more structured code, follow this guide to add an extension.

有一篇更详细的博客文章介绍了要收听的事件。不过,它仍然使用旧的方法来获取实例树。