遍历所有dbid停止我的观众

时间:2018-06-26 15:00:06

标签: autodesk-forge

因此,我有一个相当大的Revit文件,其大小为137 MB,我需要获取所有dbId,以便可以通过某些属性对其进行过滤,但是由于dbId的数量太长。是否可以事先过滤Dbid或获取Dbid的真正快速方法。目前,我将这段代码用于dbid提取。

  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
  }

是否有更好的快速提取双标的方法?

1 个答案:

答案 0 :(得分:0)

建议改用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 ) );