Autodesk forge 在所有DBID上循环会停止我的查看器
因此,我有一个137MB的相当大的revit文件,我需要获取所有DBID,以便可以按特定属性对其进行过滤,但由于DBID的数量太多,所以需要花费很长时间。是否可以预先过滤DBID,或者使用一种快速获取DBID的方法。目前,我将这段代码用于dbid提取Autodesk forge 在所有DBID上循环会停止我的查看器,autodesk-forge,Autodesk Forge,因此,我有一个137MB的相当大的revit文件,我需要获取所有DBID,以便可以按特定属性对其进行过滤,但由于DBID的数量太多,所以需要花费很长时间。是否可以预先过滤DBID,或者使用一种快速获取DBID的方法。目前,我将这段代码用于dbid提取 getDbIds() { let dictionary = this.instancetree.nodeAccess.dbIdToIndex let dbids = [] for (let i = 0; i < O
getDbIds() {
let dictionary = this.instancetree.nodeAccess.dbIdToIndex
let dbids = []
for (let i = 0; i < Object.keys(dictionary).length; i++) {
let nochildCondition = this.instancetree.getChildCount(dictionary[i]);
if (nochildCondition !== 0) {
continue
}
dbids.push(dictionary[i])
}
return dbids
}
getDbIds(){
让dictionary=this.instancetree.nodeAccess.dbIdToIndex
让dbids=[]
for(设i=0;i
有没有更好的快速提取DBID的方法?建议使用
TnstanceTree\enumNodeChildren()
获取节点树中的子节点。下面的代码片段用于我们的演示项目,希望对您有所帮助
function getLeafNodes( model, dbIds ) {
return new Promise( ( resolve, reject ) => {
try {
const instanceTree = model.getData().instanceTree
dbIds = dbIds || instanceTree.getRootId();
const dbIdArray = Array.isArray( dbIds ) ? dbIds : [dbIds]
let leafIds = [];
const getLeafNodesRec = ( id ) => {
let childCount = 0;
instanceTree.enumNodeChildren( id, ( childId ) => {
getLeafNodesRec( childId );
++childCount;
})
if( childCount == 0 ) {
leafIds.push( id );
}
}
for( let i = 0; i < dbIdArray.length; ++i ) {
getLeafNodesRec( dbIdArray[i] );
}
return resolve( leafIds );
} catch (ex) {
return reject(ex)
}
})
}
getLeafNodes( viewer.model, [1] )
.then( ( leafNodes ) => {
console.log( leafNodes );
})
.catch( ( error ) => console.warn( error ) );
函数getLeafNodes(模型,dbid){
返回新承诺((解决、拒绝)=>{
试一试{
const instanceTree=model.getData().instanceTree
dbIds=dbIds | | instanceTree.getRootId();
const dbIdArray=Array.isArray(dbIds)?dbIds:[dbIds]
设leafIds=[];
常量GetLeafNodeSec=(id)=>{
让childCount=0;
instanceTree.enumNodeChildren(id,(childId)=>{
getleaftnodesrec(childId);
++儿童计数;
})
if(childCount==0){
推(id);
}
}
for(设i=0;i