问题描述
我有兴趣获取所有dbId元素的属性.为此,我只是循环遍历dbId数组,并使用伪造查看器.
I'm interested to get the properties of all dbId elements. For this purpose I'm simply looping over my array of dbIds and use the getProperties
function provided by the Forge Viewer.
someFunction() {
const instanceTree = this.viewer.model.getData().instanceTree;
const allDbIds = Object.keys(instanceTree.nodeAccess.dbIdToIndex);
console.log('all DbIds');
console.log(allDbIds);
// This will give the correct Properties
// this.viewer.getProperties(5, (result) => {
// console.log(result)
// })
allDbIds.forEach((dbId) => {
this.viewer.getProperties(dbId, (result) => {
console.log('result:');
console.log(result);
}, (err) => {
console.log('err');
console.log(err);
});
});
}
当我直接访问特定的dbId时,将获得正确的属性数组.但是,当遍历所有dbId并调用getProperties
函数时,只有前两个dbId返回属性,而其他所有dbId仅返回空数组.另外,前两个数组很大,并且似乎包含其他属性. -> 链接到控制台输出
When I access a specific dbId directly I get the correct property array. However when looping over all dbIds and calling the getProperties
function only the first two dbIds are returning properties and all the others are only returning empty arrays. Additionally the first two arrays are way to big and seem to contain the other properties. --> Link to console output
有人知道我在这里做错了吗?已经谢谢你了!
Does somebody know what I'm doing wrong here? Thanks already!
推荐答案
除了在客户端页面上迭代属性外,更好的方法可能是通过Model Derivative API一次查询所有属性.请参阅以下参考:
Instead of iterating properties on the client page, a better approach might be to query all properties at once via the Model Derivative API. See these references:
https://developer.autodesk.com/en/docs/model-derivative/v2/reference/http/urn-metadata-GET/
这篇关于遍历所有ID时获取ID属性的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!