我有一個擴展,它用一個文本字段和一個按鈕加載一個對接面板。該按鈕的功能是顯示文本字段中給出的項目名稱的DB-ID。Autodesk Forge如何從名稱獲取dbid
喜歡的東西: 橡膠= 2130
,其中橡膠是輸入和2130(DB-ID)將輸出
我怎樣才能做到這一點?
在此先感謝。
我有一個擴展,它用一個文本字段和一個按鈕加載一個對接面板。該按鈕的功能是顯示文本字段中給出的項目名稱的DB-ID。Autodesk Forge如何從名稱獲取dbid
喜歡的東西: 橡膠= 2130
,其中橡膠是輸入和2130(DB-ID)將輸出
我怎樣才能做到這一點?
在此先感謝。
建議使用.search()
方法,這是一種支持方式:
viewer.search('Rubber', function(dbIds){
// here the dbIds is a list of dbIds, you can handle it
callback(dbIds); // handle the results async
}, function(error){
// handle errors here...
}, ['name'] /* this array indicates the filter: search only on 'Name'*/)
而且看這裏how to improve performance搜索。
目前沒有這樣的API可用,但在這種情況下可以使用解決方法。它顯示如下:
//-- For the element type or element category like "Floor [" or "Floor"
var it = viewer.model.getData().instanceTree;
var strIdx = it.nodeAccess.strings.indexOf("Floor [");
// var strIdx = it.nodeAccess.strings.indexOf("Floor");
var nameIdx = it.nodeAccess.names.indexOf(strIdx);
for(var key in it.nodeAccess.dbIdToIndex) {
if(it.nodeAccess.dbIdToIndex[key] === nameIdx) console.log(key)
}
//-- For element name like "Floor[766598]":
var it = viewer.model.getData().instanceTree;
var eidIndex = it.nodeAccess.nameSuffixes.indexOf(766598);
for(let key in it.nodeAccess.dbIdToIndex) {
if(it.nodeAccess.dbIdToIndex[key] === eidIndex) console.log(key)
}
P.S.由於這只是一種解決方法,而不是正式的解決方案。您將不得不使用它,風險自負。