如何检索Forge Viewer objectTree? [英] How to Retrieve Forge Viewer objectTree?
问题描述
我的目标是通过根据我在revit中创建的线条向查看器添加新的几何形状来突出显示一个房间,就像在这里
My goal is to highlight a room by adding new geometry to the viewer based on lines I have created in revit like they do here Link
但是我不知道如何访问这些行ID. 我知道它们在revit(element_id)中是什么,但不知道如何将它们映射为dbid.
but i can not figure out how to access those lines ids. I know what they are in revit (element_id) but not how they are mapped as dbid.
遵循此我想访问扩展中的objectTree来查找,但是它总是以未定义的形式返回.
I want to access the objectTree in my extension to find out, but it always comes back as undefined.
var tree;
//old way - viewer is your viewer object - undefined
viewer.getObjectTree(function (objTree) {
tree = objTree;
});
//2.5-未定义
var instanceTree = viewer.model.getData().instanceTree;
var rootId = this.rootId = instanceTree.getRootId();
//-未定义
var objectTree = viewer.getObjectTree();
谁能告诉我它是否仍然适用于我,我正在使用API的v2进行rvt转换为svf和2.9的viewer3D.js
Can anyone tell me if its still works for them I am using the v2 of the API for the rvt conversion to svf and 2.9 of the viewer3D.js
请注意,如果我将其命名,则可以看到dbid列表
note I can see a list of dbid if I call this
var model = viewer.impl.model;
var data = model.getData();
var fragId2dbIdArray = data.fragments.fragId2dbId ;
但无法映射回Revit element_id
but have no way of mapping back to the Revit element_id
推荐答案
从2.9版开始,此功能仍然有效.这是我的控制台:
As of version 2.9 this is still working. Here's my console:
您可以尝试以下两种操作:
Here's a couple of things you can try:
-
viewer
是否未定义?抓住viewer
时您处在正确的范围内吗? - 必须先加载文档,然后才能获取实例树.加载文档后,将触发一个名为
Autodesk.Viewing.GEOMETRY_LOADED_EVENT
的事件,然后您就可以开始操作实例树了.
- Is
viewer
undefined? Are you in the correct scope when grabbing theviewer
? - 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.
只需执行以下操作:
viewer.addEventListener(Autodesk.Viewing.GEOMETRY_LOADED_EVENT, function () {
var instanceTree = viewer.model.getData().instanceTree;
});
有关更结构化的代码,请遵循本指南添加扩展名.
For more structured code, follow this guide to add an extension.
有一个更详细的博客文章在哪个事件上收听.不过,它仍然使用旧方法来获取实例树.
There's a more detailed blog post on which event to listen for. It's still using the old way to get instance tree, though.
这篇关于如何检索Forge Viewer objectTree?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!