autodesk-forge - 如何按材料过滤,例如混凝土或钢墙
问题描述
我使用一个大的 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。
解决方案
这是一个调用的函数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);
});
检查她的参考资料:
- https://forge.autodesk.com/blog/getbulkproperties-method
- https://forge.autodesk.com/blog/search-method-performance
- https://developer.autodesk.com/en/docs/viewer/v2/reference/javascript/viewer3d/
希望能帮助到你。
推荐阅读
- javascript - 使用 Jquery 根据 td 变量值更改行颜色
- excel - 无法双击打开现有的 excel 2013 文档
- android - 当连接->数据发送到应用程序->断开连接并重复时,BLE设备被强制取消配对
- android - 无法从 Google Play 控制台中删除“内部测试轨道”构建
- c++ - 将浮点数转换为精确且无公差的字符串
- java - 我在spring.xml中定义了一个bean,我想通过@Autowired在java代码中使用这个bean,但它失败了
- python - 使用单个 x 轴从一个数据帧绘制多个图 - Python
- c - 为什么存在系统调用
- amazon-web-services - 延迟对特定数据的 Lambda 执行
- javascript - NPM 实时服务器不会加载我的项目网站