walls = FilteredElementCollector(doc, level.Id).OfCategory(BuiltInCategory.OST_Walls).WhereElementIsNotElementType().ToElements()
时间: 2024-03-28 22:37:29 浏览: 8
这段代码使用了Revit API中的FilteredElementCollector类,它是一个用于过滤Revit文档中元素的类。在这里,我们使用FilteredElementCollector来获取文档中指定level的所有墙体元素。具体来说,OfCategory方法用于指定要获取的元素类别,这里指定为OST_Walls,表示墙体类别。WhereElementIsNotElementType方法用于过滤掉类型元素,只获取实例元素。ToElements方法用于将过滤后的元素集合转换为一个Element列表,以便进一步操作。最终,walls变量将保存获取到的所有墙体元素。
相关问题
walls.size()
`walls.size()` 表示围墙的数量,`size()` 方法是 List 接口中的方法,用于获取列表的大小,即元素的数量。在这里,`walls` 是一个 List 类型的变量,它存储了多个 Wall 类型的对象(即围墙),`walls.size()` 返回的就是围墙的数量。这里使用了 `for` 循环遍历所有的围墙,判断坦克是否与围墙相交。
create_walls(){ const g = []; for(let r = 0; r < this.rows; r ++ ){ g[r] = []; for(let c = 0; c < this.cows; c ++ ){ g[r][c] = false; } } //四周加墙 for(let r = 0; r < this.rows; r ++ ){ g[r][0] = g[r][this.cols - 1] = true; } for(let c = 0; c < this.cols; c ++ ){ g[0][c] = g[this.rows - 1][c] = true; } //随机化 for(let i = 0; i < this.inner_walls_count; i ++){ for (let j = 0; j < 1000; j ++){ let r = parseInt(Math.random() * this.rows); let c = parseInt(Math.random() * this.cols); if(g[r][c] || r == this.rows - 2 && c == 1 || c == this.cols - 2 && r == 1){ continue; } g[r][c] = g[this.rows - 1 - r][this.cols - 1 -c] = true; break; } } const copy_g = JSON.parse(JSON.stringify(g));//深拷贝 if(!this.check_connectivity(copy_g, this.rows - 2, 1, 1, this.cols - 2)){ return false; } for(let r = 0; r < this.rows; r ++ ){ for(let c = 0; c < this.cols; c ++ ){ if(g[r][c]){ this.walls.push(new Wall(r, c, this)); } } } return true; }翻译成Java
以下是将 JavaScript 代码转换为 Java 代码后的结果:
public boolean createWalls() {
boolean[][] g = new boolean[this.rows][this.cols];
for (int r = 0; r < this.rows; r++) {
for (int c = 0; c < this.cols; c++) {
g[r][c] = false;
}
}
// 四周加墙
for (int r = 0; r < this.rows; r++) {
g[r][0] = g[r][this.cols - 1] = true;
}
for (int c = 0; c < this.cols; c++) {
g[0][c] = g[this.rows - 1][c] = true;
}
// 随机化
for (int i = 0; i < this.inner_walls_count; i++) {
for (int j = 0; j < 1000; j++) {
int r = (int) (Math.random() * this.rows);
int c = (int) (Math.random() * this.cols);
if (g[r][c] || (r == this.rows - 2 && c == 1) || (c == this.cols - 2 && r == 1)) {
continue;
}
g[r][c] = g[this.rows - 1 - r][this.cols - 1 - c] = true;
break;
}
}
boolean[][] copy_g = new boolean[this.rows][this.cols];
for (int r = 0; r < this.rows; r++) {
for (int c = 0; c < this.cols; c++) {
copy_g[r][c] = g[r][c];
}
}
if (!this.checkConnectivity(copy_g, this.rows - 2, 1, 1, this.cols - 2)) {
return false;
}
for (int r = 0; r < this.rows; r++) {
for (int c = 0; c < this.cols; c++) {
if (g[r][c]) {
this.walls.add(new Wall(r, c, this));
}
}
}
return true;
}