By Joe Ye
As creating a stirrup rebar shape family is not so easy. Users would like to sketch up the shape of the stirrup within a column. This article introduce how to create a stirrup by several model curves within a column.
using System; using System.Collections.Generic; using System.Linq; using System.Text; using Autodesk.Revit.ApplicationServices; using Autodesk.Revit.UI; using Autodesk.Revit.DB.Structure; using Autodesk.Revit.DB; using Autodesk.Revit.UI.Selection; namespace MyCreateRebar { [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) { UIApplication uiApp = commandData.Application; Selection sel = uiApp.ActiveUIDocument.Selection; Application app = uiApp.Application; Document doc = uiApp.ActiveUIDocument.Document; RebarBarType barType = null; RebarHookType hookType = null; Transaction transaction = new Transaction(doc, "CreateRebar Tool"); try { transaction.Start(); IList curves1 = new List(); ElementSet eleset = sel.Elements; foreach (Element e in eleset) { if (e is ModelLine) { Line l = (e as ModelLine).GeometryCurve as Line; Line line = app.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 = sel.PickObject(ObjectType.Element); FamilyInstance hostFi = doc.get_Element(hasPickOne.ElementId) as FamilyInstance; Rebar rebar = CreateRebar1(uidoc, 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 curves, FamilyInstance column, RebarBarType barType, RebarHookType hookType) { LocationPoint location = column.Location as LocationPoint; XYZ origin = location.Point; Rebar rebar = Rebar.CreateFromCurves(uidoc.Document, RebarStyle.StirrupTie, barType, hookType, hookType, column, new XYZ(0, 0, 1), curves, RebarHookOrientation.Left, RebarHookOrientation.Left, true, true); return rebar; } }

Leave a Reply