2017-10-12 1 views
0

2d DWG에서 번역 된 SVF 파일이 있고 Viewer에 성공적으로로드되었습니다.[Autodesk Forge 뷰어] 지정된 레이어에있는 객체의 dbId를 가져 오는 방법

이제 레이어의 일부 객체의 속성/속성을 쿼리하고 싶습니다. 여기

내가 지금까지 한 일이다

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) 

모든 제안에 감사드립니다.

답변

0

현재로서는 불가능할 수도 있습니다. 이 게시물을 참조하십시오 :

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

+0

이것은 정말 나쁜 소식입니다. 내 현재 해결 방법은 모든 dbIds 통해 이동하여 일치하는 하나를 선택합니다. 내 대답을보십시오. –

0

이슨 강의 대답에 따르면,이를 달성하기 위해 공식적인 방법이 없습니다. 그래서 남은 유일한 길은 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 
    }); 
+0

멋져 보이지만 대신'viewer.search' 또는'viewer.getBulkProperties'를 사용하라고 조언하고 싶습니다. 이 경우 성능이 향상 될 수 있습니다. 이 블로그 (https://forge.autodesk.com/blog/getbulkproperties-method –

+0

)를 참조하십시오.이 해결 방법이 모든 2D 모델에서 작동하지 않을 수도 있습니다. 'InstanceTree'가없는 그들 중 일부는'model.getProperties'에서 깨질 것입니다. –

관련 문제