Revit 2024 Python API创建墙体线荷载报错:hostElemId不被允许
问题解决:Revit API创建墙体线荷载报错"hostElemId is not permitted for this type of load"
问题描述
尝试用Python通过Revit 2024 API在墙体上创建线荷载时触发报错:hostElemId is not permitted for this type of load,原代码如下:
import clr import Autodesk.Revit.DB from Autodesk.Revit.DB import * from Autodesk.Revit.DB.Structure import LineLoad doc = __revit__.ActiveUIDocument.Document all_eq = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Walls).WhereElementIsNotElementType().ToElements() locCrvs = [] #Create an empty list to store the curves lLoad = [] t = Transaction(doc, "Transaction Name") t.Start() for w in all_eq: locCrvs = w.Location.Curve EleID = w.Id lLoad.append(LineLoad.Create(doc, EleID, locCrvs, XYZ(0,0,-1), XYZ(0,1,0), None)) t.Commit()
报错原因及解决方法
核心问题
- 非结构墙无法承载荷载:Revit线荷载仅允许施加在结构墙上,原代码过滤了所有墙体,包含普通建筑墙,这类墙体不能作为荷载宿主。
- 荷载类型参数缺失:
LineLoad.Create最后一个参数LineLoadType不能传None,必须传入有效的线荷载类型实例,否则Revit无法识别荷载属性。
修正后的代码
import clr import Autodesk.Revit.DB from Autodesk.Revit.DB import * from Autodesk.Revit.DB.Structure import LineLoad, LineLoadType doc = __revit__.ActiveUIDocument.Document # 仅过滤结构墙(承载墙) all_struct_walls = FilteredElementCollector(doc)\ .OfCategory(BuiltInCategory.OST_Walls)\ .WhereElementIsNotElementType()\ .Where(lambda w: w.WallType.Kind == WallKind.Bearing)\ .ToElements() # 获取项目中已有的线荷载类型,无则创建新类型 load_type = FilteredElementCollector(doc)\ .OfClass(LineLoadType)\ .FirstElement() if not load_type: load_type = LineLoadType.Create(doc, "Custom Line Load") lLoad = [] t = Transaction(doc, "Create Wall Line Loads") t.Start() for w in all_struct_walls: loc_crv = w.Location.Curve elem_id = w.Id # 传入有效的LineLoadType实例 line_load = LineLoad.Create(doc, elem_id, loc_crv, XYZ(0,0,-1), XYZ(0,1,0), load_type) lLoad.append(line_load) t.Commit()
关键说明
- 结构墙筛选:通过
WallType.Kind == WallKind.Bearing确保只处理可承载荷载的结构墙,解决"hostElemId is not permitted"报错。 - 荷载类型处理:优先获取项目内置的线荷载类型,若不存在则创建自定义类型,避免参数缺失问题。
- 荷载向量:
XYZ(0,0,-1)代表竖向向下的荷载力,XYZ(0,1,0)代表绕Y轴的弯矩,可根据需求调整。
内容的提问来源于stack exchange,提问作者John
相关产品推荐
相关产品推荐

