【问题标题】:[Autodesk Forge viewer]How to get the dbIds of the objects in a specified layer[Autodesk Forge viewer]如何获取指定图层中对象的dbIds
【发布时间】:2018-03-24 04:48:35
【问题描述】:

我有一个从2d DWG 翻译的SVF 文件并成功加载到Viewer 中。

现在我想查询图层中某些对象的属性/属性。

这是我到目前为止所做的:

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)

欢迎提出任何建议。

【问题讨论】:

    标签: javascript autodesk-forge autodesk-viewer


    【解决方案1】:

    很遗憾,目前可能无法执行此操作。请参考这篇文章:

    How to get a list of dbids contained in a layer?

    【讨论】:

    • 这真是个坏消息。我目前的解决方法是遍历所有 dbIds 并选择匹配的一个。请参阅上面的答案。
    【解决方案2】:

    根据Eason Kang的回答,没有官方方法可以实现这一点。所以剩下的唯一方法就是迭代 dbIdList。代码如下:

    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
        });
    

    【讨论】:

    • 看起来不错,但我建议您改用viewer.searchviewer.getBulkProperties。在这种情况下它可能有更好的性能。请参考此博客:forge.autodesk.com/blog/getbulkproperties-method
    • 顺便说一句,我发现这种解决方法可能不适用于所有 2D 模型。其中一些没有InstanceTree 将在model.getProperties 中被破坏。
    猜你喜欢
    • 2017-01-29
    • 2020-01-16
    • 2020-08-06
    • 1970-01-01
    • 2017-05-05
    • 2021-02-21
    • 2020-01-18
    • 2021-09-30
    • 2021-03-02
    相关资源
    最近更新 更多