获取 DWFX 文件的未定义实例树

Getting undefined instance tree for DWFX file

我们正在尝试获取 DWFX 文件的所有节点元素,但我们正在获取 DWFX 文件的未定义实例树。我们使用下面的代码来获取每个元素的 id。

// Try to get instance tree for DWFX file
    var model = this.viewer.model;
    var modelData = model.getData();
    var it = modelData.instanceTree;  // get instance tree


    We have used another way to get element node id for DWFX file. (In that case, we are getting only panel label id for DWFX file) But that logic is not working for all DWFX files.

// Try to get all ids for DWFX file
    var model = this.viewer.model;
    var modelData = model.getData();
    var allIds = modelData.stringDbIds;  // get all ids 


    Please us know If I am using wrong approach to get all elements for DWFX file.

您需要等待 Autodesk.Viewing.OBJECT_TREE_CREATED_EVENT 事件以确保 instanceTree 在您加载的模型中可用:

viewer.addEventListener(Autodesk.Viewing.OBJECT_TREE_CREATED_EVENT, function () {
    var model = this.viewer.model;
    var modelData = model.getData();
    var it = modelData.instanceTree;  
    console.log(it)
})

在某些情况下,如果您打算访问组件的几何形状,您可能还需要等待 Autodesk.Viewing.GEOMETRY_LOADED_EVENT 事件.这是一篇可能相关的文章:Asynchronous viewer events notification