很多的时候我们希望给Revit的构件配筋, 通过编程的方式可以将你用手工绘制的模型线转化成箍筋。非常方便直观。
我们调用Rebar.CreateFromCurves() 函数来创建箍筋。
函数定义如下:
public static Rebar CreateFromCurves(
Document doc,
RebarStyle style,
RebarBarType barType,
RebarHookType startHook,
RebarHookType endHook,
Element host,
XYZ norm,
IList<Curve> curves,
RebarHookOrientation startHookOrient,
RebarHookOrientation endHookOrient,
bool useExistingShapeIfPossible,
bool createNewShape
)
创建箍筋需要注意的几个输入参数的理解:
第二个参数( RebarStyle style,)是 选择钢筋类型, 对于箍筋需要设置为: RebarStyle.StirupTie. 如果对于直线钢筋或纵筋设置为RebarStyle.Standard
第七个参数( XYZ norm) 是箍筋坐在平面的法向量方向。
请看下面的代码。
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)] [Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)] public class Command1 : IExternalCommand { public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { RebarBarType barType = null; RebarHookType hookType = null; Document doc = commandData.Application.ActiveUIDocument.Document; Transaction transaction = new Transaction(doc, "CreateRebar Tool"); try { transaction.Start(); IList<Curve> curves1 = new List<Curve>(); ElementSet eleset = commandData.Application.ActiveUIDocument.Selection.Elements; //需要确保这些选择的线是首尾相连的。 foreach (Element e in eleset) { if (e is ModelLine) { Line l = (e as ModelLine).GeometryCurve as Line; Line line = doc.Application.Create.NewLineBound(l.get_EndPoint(0), l.get_EndPoint(1)); curves1.Add(line); } } foreach (RebarBarType bt in doc.RebarBarTypes) { barType = bt; break; } foreach (RebarHookType ht in doc.RebarHookTypes) { hookType = ht; } { Reference hasPickOne = commandData.Application.ActiveUIDocument.Selection.PickObject(Autodesk.Revit.UI.Selection.ObjectType.Element); FamilyInstance hostFi = doc.get_Element(hasPickOne.ElementId) as FamilyInstance; Rebar rebar = CreateRebar1(commandData.Application.ActiveUIDocument, curves1, hostFi, barType, hookType); } } catch (Exception ex) { message += ex.Message; return Autodesk.Revit.UI.Result.Failed ; } finally { transaction.Commit(); } return Result.Succeeded ; } Rebar CreateRebar1( Autodesk.Revit.UI.UIDocument uidoc, IList<Curve> curves, FamilyInstance column, RebarBarType barType, RebarHookType hookType) { LocationPoint location = column.Location as LocationPoint; XYZ origin = location.Point; Rebar rebar = Rebar.CreateFromCurves(uidoc.Document, Autodesk.Revit.DB.Structure.RebarStyle.StirrupTie, barType, hookType, hookType, column, new XYZ(0,0,1), curves, RebarHookOrientation.Left, RebarHookOrientation.Left, true, true); return rebar; } }