必看部分:
Document获取:
必看文章
基础部分:
创建楼板
基本思路:
- 首先添加引用
- 获取当前项目文档
- 开启事务
- 获取楼板类型
- 获取标高
- 创建楼板
实现代码:
import Autodesk
from Autodesk.Revit.DB import *
doc = __revit__.ActiveUIDocument.Document
levels = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Levels).WhereElementIsNotElementType().ToElements()
slabs = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Floors).WhereElementIsElementType().ToElements()
p_1 = XYZ(0, 0, 0)
p_2 = XYZ(0, 10, 0)
p_3 = XYZ(10, 10, 0)
p_4 = XYZ(10, 0, 0)
line_1 = Line.CreateBound(p_1, p_2)
line_2 = Line.CreateBound(p_2, p_3)
line_3 = Line.CreateBound(p_3, p_4)
line_4 = Line.CreateBound(p_4, p_1)
for level in levels:
elevation = level.get_Parameter(BuiltInParameter.LEVEL_ELEV).AsDouble()
if elevation == 6000/304.8:
level_0 = level
for slab in slabs:
name = slab.get_Parameter(BuiltInParameter.SYMBOL_NAME_PARAM).AsString()
if name == '常规 - 150mm':
floorType = slab
curveArray = CurveArray()
curveArray.Append(line_1)
curveArray.Append(line_2)
curveArray.Append(line_3)
curveArray.Append(line_4)
t = Transaction(doc, '创建楼板')
t.Start()
slab_new = doc.Create.NewFloor(curveArray, floorType, level_0, Structure.StructuralType.Footing)
offset = slab_new.get_Parameter(BuiltInParameter.FLOOR_HEIGHTABOVELEVEL_PARAM)
offset.Set(0)
t.Commit()
总结:
1.创建构件需要开启事务(Transaction)
2.确定标高及指定楼板类型存在
欢迎大家添加交流QQ群: 17075104
一起学习