首页 > 解决方案 > 如何按材料过滤,例如混凝土或钢墙

问题描述

我使用一个大的 revit 文件,当我通过getProperties(id).
是否有按属性过滤的最佳实践方法,因为它会导致性能问题?
我的做法:

      /**
   * Looks inside the Autodesk-Database for the material category and looks if the material is concrete.
   * Returns asynchronously an array with all ids which represent parts built with concrete material
   * @returns {Promise<Array | void>}
   */
  async getConcreteIds() {
    const wallfloorids = await this.getWallFloorIds()
    let concreteIds = []
    let filterCategory = 'Materialien und Oberflächen'
    let filterValue = 'Concrete'
    let promises = wallfloorids.map(id => {
      let p1 = this.getProperties(id)
      return p1
        .then((props) => {
          console.log(props)
          for (let prop of props) {
            let filtercondition =
              prop.displayCategory === filterCategory &&
              prop.displayValue.contains(filterValue)
            if (filtercondition) {
              concreteIds.push(id)
            }
          }
        })
        .catch(err => console.log(err))
    })
    return Promise.all(promises)
      .then( concreteIds)
      .catch(err => console.log('Err', err))
  }

  /**
   * acquires properties of a part out of Autodesk Database
   * @param dbId
   * @returns {Promise<any>}
   */
  getProperties(dbId): Promise<any> {
    return new Promise((resolve, reject) => {
      this.viewer.getProperties(
        dbId,
        args => {
          resolve(args.properties)
        },
        reject
      )
    })

  }

直到最近,当我使用一个小文件时,这才有效,因为这个小文件没有那么多的属性和 dbId。

标签: autodesk-forge

解决方案


这是一个调用的函数Viewer3D#search,可用于搜索具有特定值的属性:

viewer.search('Concrete', 
   function(dbIds) {
      console.log( dbIds );
   },
   function( error ) {
      console.error( error )
   },
   ['Structural Material']
);

或者,您可以使用Viewer3D#getBulkProperties来获取dbIds与传递的属性名称匹配的给定属性:

viewer.model.getBulkProperties(dbIds, ['Structural Material'],
   function(elements){
     let dbIds = [];
     let filterCategory = "Materials and Finishes";
     let filterValue = 'Concrete';

     for(let i=0; i<elements.length; i++) {
       const prop = elements[i].properties[0];
       const dbId = elements[i].dbId;
       if(prop.displayCategory === filterCategory && prop.displayValue.contains(filterValue)) {
         dbIds.push( dbId );
       }
     }
     console.log(dbIds);
   });

检查她的参考资料:

希望能帮助到你。


推荐阅读