简体   繁体   English

[Autodesk Forge查看器]如何获取指定层中对象的dbId

[英][Autodesk Forge viewer]How to get the dbIds of the objects in a specified layer

I have a SVF file translated from 2d DWG and successfully loaded in a Viewer . 我有一个从2d DWG转换而来的SVF文件,并已成功加载到Viewer

Now I want to query attributes/properties of some objects in a layer. 现在,我要查询图层中某些对象的属性/属性。

Here is what I've done so far: 到目前为止,这是我所做的:

let layer = viewer.model.getLayersRoot().children.find(x=> x.name==='Marker');//find the layer named by 'Marker'----{name: "Marker", index: 72, id: 71, isLayer: true}
let objectTree = viewer.model.getData().instanceTree;//get the Object Tree and its One-dimensional array of dbIdList
// stuck here
// looking for some method like objectTree.getIdListInLayer(layerId)

Any suggestion is appreciated. 任何建议表示赞赏。

Unfortunately, it might not be possible to do this currently. 不幸的是,当前可能无法执行此操作。 Please refer this post: 请参考这篇文章:

How to get a list of dbids contained in a layer? 如何获取图层中包含的Dbid列表?

According to Eason Kang's answer, there is no official approach to achieve this. 根据Eason Kang的回答,目前尚无官方方法来实现这一目标。 So the only way left is to iterate the dbIdList. 因此,剩下的唯一方法是迭代dbIdList。 Here is the code: 这是代码:

function query(dbId, model, layerName) {
    if (!dbId) return Promise.resolve(null);
    return new Promise(resolve => {
        model.getProperties(dbId, x => {
            let layerProp = x.properties.find(x => x.displayName === 'Layer' && x.displayValue === layerName);
            resolve(!!layerProp ? x : null);
        });
    });
}

Promise.all(Object.keys(objectTree.nodeAccess.dbIdToIndex).map(dbId => query(dbId = dbId - 0, viewer.model, layerName = 'Marker')))
    .then(function(resultList) {
        resultList = resultList.filter(x => !!x);
        console.table(resultList); //this is all the objects in the Marker layer
    });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM