简体   繁体   中英

[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 .

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?

According to Eason Kang's answer, there is no official approach to achieve this. So the only way left is to iterate the 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
    });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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