[英]How to get all the DB-IDs in Autodesk Forge
I need to get all the DB-Ids from the Autodesk forge model. 我需要从Autodesk forge模型中获取所有DB-Id。 I have referred the code from https://forge.autodesk.com/cloud_and_mobile/2015/12/select-all-elements-in-the-viewer-with-view-and-data-api-with-javascript.html
我已经从https://forge.autodesk.com/cloud_and_mobile/2015/12/select-all-elements-in-the-viewer-with-view-and-data-api-with-javascript.html引用了代码
I also have tried it in my own extension and the code is as follows. 我也在自己的扩展程序中尝试过,代码如下。
AutodeskNamespace("Autodesk.ADN.Viewing.Extension"); Autodesk.ADN.Viewing.Extension.Color = function(viewer, options) { Autodesk.Viewing.Extension.call(this, viewer, options); var _self = this; var _viewer = viewer; var instanceTree = viewer.model.getData().instanceTree; var rootId = this.rootId = instanceTree.getRootId(); _self.load = function() { getgetAlldbIds(rootId); }; function getAlldbIds(rootId) { var alldbId = []; if (!rootId) { return alldbId; } var queue = []; queue.push(rootId); while (queue.length > 0) { var node = queue.shift(); alldbId.push(node); instanceTree.enumNodeChildren(node, function(childrenIds) { queue.push(childrenIds); }); } console.log(alldbId); } };
But I'm getting an error in Developer Tools as cannot read property 'getData' of null
where do you think I'm going wrong. 但是我在开发人员工具中遇到错误,因为
cannot read property 'getData' of null
您认为我在哪里出错。 thanks in advance. 提前致谢。
The problem must be that the model is not fully loaded, so you should wait for that event (Autodesk.Viewing.GEOMETRY_LOADED_EVENT). 问题必须是模型未完全加载,因此您应该等待该事件(Autodesk.Viewing.GEOMETRY_LOADED_EVENT)。 It might be better to wait for the object tree created event as well (Autodesk.Viewing.OBJECT_TREE_CREATED_EVENT) - see discussion here: How to Retrieve Forge Viewer objectTree?
也最好等待对象树创建事件(Autodesk.Viewing.OBJECT_TREE_CREATED_EVENT)-请参见此处的讨论: 如何检索Forge Viewer objectTree?
By the way, there is an easier way now to get all the dbIds: Get all database id's in the model 顺便说一下,现在有一种更简单的方法来获取所有dbId: 在模型中获取所有数据库ID。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.