/// <summary> /// Present the main dialog for user to prepare the parameters for Rebar creation, /// and after that if user click the OK button, a new Rebar will be created. /// </summary> public void Execute() { using (NewRebarForm form = new NewRebarForm(m_rvtUIDoc.Document)) { if (DialogResult.OK == form.ShowDialog()) { RebarBarType barType = form.RebarBarType; RebarShape barShape = form.RebarShape; List <Autodesk.Revit.DB.XYZ> profilePoints = m_geometryData.ProfilePoints; Autodesk.Revit.DB.XYZ origin = profilePoints[0]; Autodesk.Revit.DB.XYZ yVec = profilePoints[1] - origin; Autodesk.Revit.DB.XYZ xVec = profilePoints[3] - origin; m_createdRebar = Rebar.CreateFromRebarShape(m_rvtUIDoc.Document, barShape, barType, m_rebarHost, origin, xVec, yVec); LayoutRebar(); } } }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { var uiApp = commandData.Application; var uiDoc = uiApp.ActiveUIDocument; var app = uiApp.Application; var doc = uiDoc.Document; var rebarShape = new FilteredElementCollector(doc) .OfClass(typeof(RebarShape)) .Cast <RebarShape>() .First(x => x.Name == "M_00"); var rebarType = new FilteredElementCollector(doc) .OfClass(typeof(RebarBarType)) .Cast <RebarBarType>(). First(x => x.Name == "22M"); var reference = uiDoc.Selection.PickObject(ObjectType.Element, "Select element to put Rebar"); var element = doc.GetElement(reference.ElementId); var locationPoint = element.Location as LocationPoint; var centerPoint = locationPoint.Point; var xVec = new XYZ(0, 0, 1); var yVec = new XYZ(0, 1, 0); try { using (var transaction = new Transaction(doc, "Create Rebar Demo")) { transaction.Start(); var rebar = Rebar.CreateFromRebarShape(doc, rebarShape, rebarType, element, centerPoint, xVec, yVec); transaction.Commit(); } } catch (Exception e) { message = e.Message; return(Result.Failed); } return(Result.Succeeded); }
/// <summary> /// Add a multi-planar bar into corbel with given options. /// </summary> /// <param name="options">Options for Rebar Creation</param> private void PlaceMultiplanarRebar(CorbelReinforcementOptions options) { Trapezoid profileCopy = m_profile.Clone(); profileCopy.OffsetTop(-m_corbelCoverDistance - options.StirrupBarType.BarDiameter - 0.5 * options.MultiplanarBarType.BarDiameter); profileCopy.OffsetLeft(-m_corbelCoverDistance - 0.5 * options.MultiplanarBarType.BarDiameter); profileCopy.OffsetBottom(m_hostDepth - m_hostCoverDistance - options.HostStraightBarType.BarDiameter * 4 - options.StirrupBarType.BarDiameter); profileCopy.OffsetRight(-m_corbelCoverDistance - options.StirrupBarType.BarDiameter - 0.5 * options.StirrupBarType.BarDiameter); //m_profile.Draw(options.RevitDoc); //profileCopy.Draw(options.RevitDoc); XYZ origin, vx, vy; profileCopy.Boundary(out origin, out vx, out vy); XYZ vecX = vx.Normalize(); XYZ vecY = vy.Normalize(); RebarShape barshape = profileCopy.ConstructMultiplanarRebarShape(options.RevitDoc, 0.5 * options.MultiplanarBarType.StirrupTieBendDiameter); Rebar newRebar = Rebar.CreateFromRebarShape( options.RevitDoc, barshape, options.MultiplanarBarType, m_corbel, origin, vecX, vecY); XYZ extruDir = (m_extrusionLine.GetEndPoint(1) - m_extrusionLine.GetEndPoint(0)).Normalize(); double offset = m_corbelCoverDistance + options.StirrupBarType.BarDiameter + 0.5 * options.MultiplanarBarType.BarDiameter; newRebar.ScaleToBoxFor3D(origin + extruDir * (m_extrusionLine.Length - offset), vx, vy, m_extrusionLine.Length - 2 * offset); ShowRebar3d(newRebar); }
public void testRebar_FromShape() { UIDocument uiDoc = this.ActiveUIDocument; Document doc = uiDoc.Document; // Pick Rebar List <int> myListIdCategoryRebar = new List <int>(); myListIdCategoryRebar.Add((int)BuiltInCategory.OST_StructuralFraming); // Select first Element (ex beam) Reference myRefBeam = uiDoc.Selection.PickObject(ObjectType.Element, new FilterByIdCategory(myListIdCategoryRebar), "Pick a Beam..."); //Get element1 from ref Element myBeam = doc.GetElement(myRefBeam); setBeJoined(myBeam); LocationCurve myLocBeam = myBeam.Location as LocationCurve; Line centerLinebeam = myLocBeam.Curve as Line; XYZ p = centerLinebeam.GetEndPoint(0); XYZ q = centerLinebeam.GetEndPoint(1); XYZ v = p - q; XYZ v1 = v.CrossProduct(p); List <Curve> myShape = new List <Curve>() { centerLinebeam }; // Rebartype FilteredElementCollector fec1 = new FilteredElementCollector(doc) .OfClass(typeof(RebarBarType)); IEnumerable <RebarBarType> iterRebarBarTypes = fec1.Cast <RebarBarType>(); RebarBarType myRebarType = iterRebarBarTypes.First(); // RebarShape FilteredElementCollector fec3 = new FilteredElementCollector(doc) .OfClass(typeof(RebarShape)); IEnumerable <RebarShape> iterRebarBarShapes = fec3.Cast <RebarShape>(); RebarShape myRebarShape = iterRebarBarShapes.First(); // Hooktype FilteredElementCollector fec2 = new FilteredElementCollector(doc) .OfClass(typeof(RebarHookType)); IEnumerable <RebarHookType> iterRebarHookTypes = fec2.Cast <RebarHookType>(); RebarHookType myRebarHookType = iterRebarHookTypes.First(); XYZ ORIGIN = new XYZ(q.X, q.Y, q.Z - 25 / 304.8); using (Transaction trans = new Transaction(doc, "rebar test")) { trans.Start(); Rebar bar = Rebar.CreateFromRebarShape(doc, myRebarShape, myRebarType, myBeam, ORIGIN, v, new XYZ(0, 0, 1)); doc.Regenerate(); List <Curve> myCenterLineOfRebar = bar.GetCenterlineCurves(false, false, false, MultiplanarOption.IncludeOnlyPlanarCurves, 0) as List <Curve>; trans.Commit(); } }
public void GetFraming() { if (VolumeParametrA < 100) { throw new ArgumentException("Значение A должно быть больше 100"); } if (VolumeParametrB < 50) { throw new ArgumentException("Значение B должно быть больше 50"); } if (RebarSpace < 50) { throw new ArgumentException("Значение RebarSpace должно быть больше 50"); } Options geoOptions = new Options() { View = doc.ActiveView, IncludeNonVisibleObjects = true }; GeometryElement geoElement = host.get_Geometry(geoOptions); FaceArray faceArray = new FaceArray(); foreach (GeometryObject geoObject in geoElement) { Solid geoSolid = geoObject as Solid; if (null != geoSolid) { faceArray = geoSolid.Faces; } } RebarShape rebarShape = GetRebarShape(NameRebarShape); RebarBarType rebarBarType = GetRebarBarType(NameRebarBarType); using (TransactionGroup tg = new TransactionGroup(doc , "TransactionGroupSlabReinforcement_3")) { tg.Start(); foreach (PlanarFace planarFace in faceArray) { if (planarFace.FaceNormal.Z == 0) { XYZ origin = GetOrigin(planarFace , VolumeParametrA / coof , NameRebarShape); using (Transaction t = new Transaction(doc, "SlabReinforcement_3")) { t.Start(); if (NameRebarShape == "Стж_Г") { XYZ xVec = planarFace.FaceNormal; XYZ yVec = -planarFace.XVector; Rebar rebar = Rebar.CreateFromRebarShape(doc, rebarShape , rebarBarType, host, origin, xVec, yVec); if (null != rebar) { bool barsOnNormalSide; if (planarFace.YVector == new XYZ(0, 1, 0)) { barsOnNormalSide = true; } else { barsOnNormalSide = false; } int numberOfBarPositions = (int)Math.Round ( ((planarFace.GetBoundingBox().Max.V - (2 * 50 / coof)) / (RebarSpace / coof) + 1) ); double spacing = RebarSpace / coof; bool includeFirstBar = true; bool includeLastBar = true; rebar.GetShapeDrivenAccessor() .SetLayoutAsNumberWithSpacing(numberOfBarPositions , spacing, barsOnNormalSide , includeFirstBar, includeLastBar); foreach (Parameter para in rebar.Parameters) { SetParametr(para); } } } if (NameRebarShape == "Стж_П") { XYZ xVec = -planarFace.XVector; XYZ yVec = -planarFace.FaceNormal; Rebar rebar = Rebar.CreateFromRebarShape(doc, rebarShape , rebarBarType, host, origin, xVec, yVec); if (null != rebar) { bool barsOnNormalSide; if (planarFace.YVector == new XYZ(0, 1, 0)) { barsOnNormalSide = true; } else { barsOnNormalSide = false; } int numberOfBarPositions = (int)Math.Round ( ((planarFace.GetBoundingBox().Max.V - (2 * 50 / coof)) / (RebarSpace / coof) + 1) ); double spacing = RebarSpace / coof; bool includeFirstBar = true; bool includeLastBar = true; rebar.GetShapeDrivenAccessor() .SetLayoutAsNumberWithSpacing(numberOfBarPositions , spacing, barsOnNormalSide , includeFirstBar, includeLastBar); foreach (Parameter para in rebar.Parameters) { SetParametr(para); } } } t.Commit(); } } } tg.Assimilate(); } }