Ejemplo n.º 1
0
        Rebar CreateRebar(Document document, FamilyInstance column, RebarBarType barType, RebarHookType hookType)
        {
            // Define the rebar geometry information - Line rebar
            LocationPoint location = column.Location as LocationPoint;
            XYZ           origin   = location.Point;
            XYZ           normal   = new XYZ(1, 0, 0);
            // create rebar 9' long
            XYZ  rebarLineEnd = new XYZ(origin.X, origin.Y, origin.Z + 9);
            Line rebarLine    = Line.CreateBound(origin, rebarLineEnd);

            // Create the line rebar
            IList <Curve> curves = new List <Curve>();

            curves.Add(rebarLine);

            Rebar rebar = Rebar.CreateFromCurves(document, RebarStyle.StirrupTie, barType, hookType, hookType,
                                                 column, origin, curves, RebarHookOrientation.Right, RebarHookOrientation.Left, true, true);

            if (null != rebar)
            {
                // set specific layout for new rebar as fixed number, with 10 bars, distribution path length of 1.5'
                // with bars of the bar set on the same side of the rebar plane as indicated by normal
                // and both first and last bar in the set are shown
                rebar.SetLayoutAsFixedNumber(10, 1.5, true, true, true);
            }

            return(rebar);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Add straight bars into corbel Host to anchor corbel stirrup bars.
        /// </summary>
        /// <param name="options">Options for Rebar Creation</param>
        private void PlaceCorbelHostBars(CorbelReinforcementOptions options)
        {
            Trapezoid profileCopy = m_profile.Clone();

            profileCopy.OffsetBottom(m_hostDepth - m_hostCoverDistance
                                     - options.HostStraightBarType.BarDiameter * 0.5
                                     - options.StirrupBarType.BarDiameter);

            //profileCopy.Draw(options.RevitDoc);

            XYZ    extruDir = (m_extrusionLine.GetEndPoint(1) - m_extrusionLine.GetEndPoint(0)).Normalize();
            double offset   = m_corbelCoverDistance + options.StirrupBarType.BarDiameter
                              + options.HostStraightBarType.BarDiameter * 0.5;
            XYZ delta = extruDir * offset;

            XYZ pt1 = profileCopy.Bottom.GetEndPoint(0) + delta;
            XYZ pt2 = profileCopy.Bottom.GetEndPoint(1) + delta;

            Curve         barLine   = Line.CreateBound(pt1, pt2);
            IList <Curve> barCurves = new List <Curve>();

            barCurves.Add(barLine);

            Rebar bars = Rebar.CreateFromCurves(
                options.RevitDoc, RebarStyle.Standard,
                options.HostStraightBarType, null, null, m_corbel.Host, extruDir, barCurves,
                RebarHookOrientation.Left, RebarHookOrientation.Left, true, true);

            bars.SetLayoutAsFixedNumber(2, m_extrusionLine.Length - 2 * offset, true, true, true);

            ShowRebar3d(bars);
        }
Ejemplo n.º 3
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            Application app = commandData.Application.Application;
            UIDocument uidoc = commandData.Application.ActiveUIDocument;
            Document doc = uidoc.Document;

            Reference pickedReference = null;
            try
            {
                pickedReference = uidoc.Selection.PickObject(ObjectType.Element, new RebarSelectFilter() , "Pick a Rebar");
            }
            catch (Autodesk.Revit.Exceptions.OperationCanceledException)
            {
                return Result.Cancelled;
            }

            Rebar rebar = doc.GetElement(pickedReference) as Rebar;
            if (!rebar.IsRebarShapeDriven() || rebar.LayoutRule == RebarLayoutRule.Single)
            {
                message = "Singe rebar and non-shape driven rebars are not supported.";
                return Result.Failed;
            }
            double rebarDiameter = rebar.GetBendData().BarDiameter;
            RebarBarType barType = doc.GetElement(rebar.GetTypeId()) as RebarBarType;

            IList<Curve> transformedCurvesFirst = Utils.GetTransformedCenterLineCurvesAtPostition(rebar, 0);
            IList<Curve> transformedCurvesLast = Utils.GetTransformedCenterLineCurvesAtPostition(rebar, rebar.NumberOfBarPositions-1);

            XYZ direction = transformedCurvesFirst.OfType<Line>().First().Direction;

            List<XYZ> rebarInBendFirstPoints = GetPointInArc(transformedCurvesFirst, rebarDiameter);
            List<XYZ> rebarInBendLastPoints = GetPointInArc(transformedCurvesLast, rebarDiameter);

            using (Transaction t1 = new Transaction(doc, "Add rebar in bend"))
            {
                t1.Start();
                for (int i = 0; i < rebarInBendFirstPoints.Count; i++)
                {
                    Line newRebarCenterline = Line.CreateBound(rebarInBendFirstPoints[i], rebarInBendLastPoints[i]);
                    IList<Curve> rebarCurve = new List<Curve>();
                    rebarCurve.Add(newRebarCenterline);
                    Rebar.CreateFromCurves(doc, RebarStyle.Standard, barType, null, null, doc.GetElement(rebar.GetHostId()), direction, rebarCurve, RebarHookOrientation.Left, RebarHookOrientation.Left, true, false);
                }
                doc.Regenerate();
                t1.Commit();
            }
            return Result.Succeeded;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// A wrap fuction which used to create the reinforcement.
        /// </summary>
        /// <param name="rebarType">The element of RebarBarType</param>
        /// <param name="startHook">The element of start RebarHookType</param>
        /// <param name="endHook">The element of end RebarHookType</param>
        /// <param name="geomInfo">The goemetry information of the rebar</param>
        /// <param name="startOrient">An Integer defines the orientation of the start hook</param>
        /// <param name="endOrient">An Integer defines the orientation of the end hook</param>
        /// <returns></returns>
        protected Rebar PlaceRebars(RebarBarType rebarType, RebarHookType startHook,
                                    RebarHookType endHook, RebarGeometry geomInfo,
                                    RebarHookOrientation startOrient, RebarHookOrientation endOrient)
        {
            Autodesk.Revit.DB.XYZ normal = geomInfo.Normal; // the direction of rebar distribution
            IList <Curve>         curves = geomInfo.Curves; // the shape of the rebar curves

            // Invoke the NewRebar() method to create rebar
            Rebar createdRebar = Rebar.CreateFromCurves(m_revitDoc, Autodesk.Revit.DB.Structure.RebarStyle.Standard, rebarType, startHook, endHook,
                                                        m_hostObject, normal, curves,
                                                        startOrient, endOrient, false, true);

            if (null == createdRebar)   // Assert the creation is successful
            {
                return(null);
            }

            // Change the rebar number and spacing properties to the user wanted
            SetRebarSpaceAndNumber(createdRebar, geomInfo.RebarNumber, geomInfo.RebarSpacing);
            return(createdRebar);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Add straight bars into corbel with given options.
        /// </summary>
        /// <param name="options">Options for Rebar Creation</param>
        private void PlaceStraightBars(CorbelReinforcementOptions options)
        {
            Trapezoid profileCopy = m_profile.Clone();

            profileCopy.OffsetTop(-m_corbelCoverDistance);
            profileCopy.OffsetLeft(-m_corbelCoverDistance
                                   - options.MultiplanarBarType.BarDiameter
                                   - options.TopBarType.BarDiameter * 0.5);
            profileCopy.OffsetBottom(m_hostDepth - m_hostCoverDistance
                                     - options.StirrupBarType.BarDiameter
                                     - options.HostStraightBarType.BarDiameter);
            profileCopy.OffsetRight(-m_corbelCoverDistance);

            //m_profile.Draw(options.RevitDoc);
            //profileCopy.Draw(options.RevitDoc);

            XYZ    extruDir = (m_extrusionLine.GetEndPoint(1) - m_extrusionLine.GetEndPoint(0)).Normalize();
            double offset   = m_corbelCoverDistance +
                              options.StirrupBarType.BarDiameter +
                              options.MultiplanarBarType.BarDiameter +
                              0.5 * options.TopBarType.BarDiameter;

            Line          vetical   = profileCopy.Vertical;
            XYZ           delta     = extruDir * offset;
            Curve         barLine   = Line.CreateBound(vetical.GetEndPoint(1) + delta, vetical.GetEndPoint(0) + delta);
            IList <Curve> barCurves = new List <Curve>();

            barCurves.Add(barLine);

            Rebar bars = Rebar.CreateFromCurves(options.RevitDoc, RebarStyle.Standard,
                                                options.TopBarType, null, null, m_corbel, extruDir, barCurves,
                                                RebarHookOrientation.Left, RebarHookOrientation.Left, true, true);

            bars.SetLayoutAsFixedNumber(options.TopBarCount + 2,
                                        m_extrusionLine.Length - 2 * offset, true, false, false);
            ShowRebar3d(bars);
        }
Ejemplo n.º 6
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            Document  doc = commandData.Application.ActiveUIDocument.Document;
            Selection sel = commandData.Application.ActiveUIDocument.Selection;

            if (sel.GetElementIds().Count == 0)
            {
                message = "Выберите арматурные стержни";
                return(Result.Failed);
            }

            Rebar bar = doc.GetElement(sel.GetElementIds().First()) as Rebar;

            if (bar == null)
            {
                message = "Выберите арматурные стержни";
                return(Result.Failed);
            }
#if R2017
            XYZ normal = bar.Normal;
#else
            RebarShapeDrivenAccessor acc = bar.GetShapeDrivenAccessor();
            XYZ normal = acc.Normal;
#endif
            RebarBarType barType = doc.GetElement(bar.GetTypeId()) as RebarBarType;

            int        rebarStyleNumber = bar.get_Parameter(BuiltInParameter.REBAR_ELEM_HOOK_STYLE).AsInteger();
            RebarStyle rebarStyle       = (RebarStyle)rebarStyleNumber;

            RebarHookType hookTypeStart   = null;
            ElementId     hookStartTypeId = bar.get_Parameter(BuiltInParameter.REBAR_ELEM_HOOK_START_TYPE).AsElementId();
            if (hookStartTypeId != null)
            {
                hookTypeStart = doc.GetElement(hookStartTypeId) as RebarHookType;
            }

            RebarHookType hookTypeEnd   = null;
            ElementId     hookEndTypeId = bar.get_Parameter(BuiltInParameter.REBAR_ELEM_HOOK_END_TYPE).AsElementId();
            if (hookEndTypeId != null)
            {
                hookTypeEnd = doc.GetElement(hookEndTypeId) as RebarHookType;
            }


            RebarBendData        rbd         = bar.GetBendData();
            RebarHookOrientation hookOrient0 = rbd.HookOrient0;
            RebarHookOrientation hookOrient1 = rbd.HookOrient1;

            Element host = doc.GetElement(bar.GetHostId());

            List <Curve> curves    = bar.GetCenterlineCurves(false, true, true, MultiplanarOption.IncludeOnlyPlanarCurves, 0).ToList();
            int          barsCount = bar.NumberOfBarPositions;

            List <ElementId> newRebarIds = new List <ElementId>();
            using (Transaction tr = new Transaction(doc))
            {
                tr.Start("Explode rebar set");
                for (int i = 0; i < barsCount; i++)
                {
#if R2017
                    Transform barOffset = bar.GetBarPositionTransform(i);
#else
                    Transform barOffset = acc.GetBarPositionTransform(i);
#endif
                    XYZ offset = barOffset.Origin;

                    Rebar newRebar = Rebar.CreateFromCurves(doc, rebarStyle, barType, hookTypeStart, hookTypeEnd, host, normal, curves,
                                                            hookOrient0, hookOrient1, true, false);
                    doc.Regenerate();
                    ElementTransformUtils.MoveElement(doc, newRebar.Id, offset);
                    newRebarIds.Add(newRebar.Id);
                }

                doc.Delete(bar.Id);

                tr.Commit();
            }

            sel.SetElementIds(newRebarIds);

            return(Result.Succeeded);
        }
        public void testRebar_FromCurve_Bot_Func(Document doc, Element myBeam, List <Face> myListFacePicked, double divideFac, double coverBar,
                                                 string myRebarShapeName, string myRebarTypeName)
        {
            LocationCurve myLocBeam = myBeam.Location as LocationCurve;

            List <XYZ> myEndPoints = getPointCenterBottomLine(doc, myBeam);

            XYZ p1 = myEndPoints[0];
            XYZ p2 = myEndPoints[1];

            XYZ    Vp1p2      = p2 - p1;
            double p1p2Length = Vp1p2.GetLength();

            // Cover bar thickness = 25
            //			double coverBar = 25/304.8;

            XYZ p1_Rb = p1 + coverBar / p1p2Length * Vp1p2;

            XYZ p2_Rb = p1 + (1 - coverBar / p1p2Length) * Vp1p2;

            p1_Rb = new XYZ(p1_Rb.X, p1_Rb.Y, p1_Rb.Z + coverBar);
            p2_Rb = new XYZ(p2_Rb.X, p2_Rb.Y, p2_Rb.Z + coverBar);



            Line centerLineBeam = Line.CreateBound(p1_Rb, p2_Rb);

            XYZ v  = p2_Rb - p1_Rb;
            XYZ p  = p1_Rb - 0.1 * v;
            XYZ v1 = new XYZ(v.Y, -1 * v.X, v.Z);
            XYZ v2 = p2_Rb - p;

            List <double> myListDisSortFace = getAndSortDisOfEndFaces(myListFacePicked, p);

            double lengSeg = myListDisSortFace[myListDisSortFace.Count() - 1] - myListDisSortFace[0];
            //		    double divideFac = 6;

            XYZ ePR1 = p + ((myListDisSortFace[0] + lengSeg / divideFac) / v2.GetLength()) * v2;
            XYZ ePR2 = p + ((myListDisSortFace[myListDisSortFace.Count() - 1] - lengSeg / divideFac) / v2.GetLength()) * v2;

            Line curveOfRebar = Line.CreateBound(ePR1, ePR2);


            List <Curve> myShape = new List <Curve>()
            {
                curveOfRebar
            };

            // RebarShape
            FilteredElementCollector fecRebarShape = new FilteredElementCollector(doc)
                                                     .OfClass(typeof(RebarShape));

            RebarShape myRebarShape = fecRebarShape.Cast <RebarShape>().
                                      First <RebarShape>(myRebarShape2 => myRebarShape2.Name == myRebarShapeName);


            // Rebartype
            FilteredElementCollector fecRebarType = new FilteredElementCollector(doc)
                                                    .OfClass(typeof(RebarBarType));
            RebarBarType myRebarType = fecRebarType.Cast <RebarBarType>().
                                       First <RebarBarType>(myRebarType2 => myRebarType2.Name == myRebarTypeName);



            // Hooktype
            FilteredElementCollector fec2 = new FilteredElementCollector(doc)
                                            .OfClass(typeof(RebarHookType));

            IEnumerable <RebarHookType> iterRebarHookTypes = fec2.Cast <RebarHookType>();

            RebarHookType myRebarHookType = iterRebarHookTypes.First();

            using (Transaction trans = new Transaction(doc, "rebar test"))

            {
                trans.Start();
                //				Rebar myRebar = Rebar.CreateFromCurvesAndShape(doc, myRebarShape, myRebarType,
                //				                                               null, null,
                //				                                               myBeam,v1,
                //				                                               myShape,
                //				                                               RebarHookOrientation.Left,
                //				                                               RebarHookOrientation.Left);
                Rebar myRebar = Rebar.CreateFromCurves(doc, RebarStyle.Standard, myRebarType,
                                                       null, null,
                                                       myBeam, v1,
                                                       myShape,
                                                       RebarHookOrientation.Left, RebarHookOrientation.Right,
                                                       true, false);


                trans.Commit();
            }
        }
Ejemplo n.º 8
0
        public void testRebar_FromCurve()
        {
            UIDocument uiDoc = this.ActiveUIDocument;
            Document   doc   = uiDoc.Document;

//			// prompt select face
//
//			Reference myRef = uiDoc.Selection.PickObject(ObjectType.Face);
//
//			// Get element by pickface
//			Element e = doc.GetElement(myRef) as Element;
//
//
//			//Get GeoObject from element;
//			GeometryObject myGeoObj =  e.GetGeometryObjectFromReference(myRef) as Face;
//
//			//Get face from element Object:
//			Face myPickedFace = myGeoObj as Face;
//
//			XYZ myNorVecFace = myPickedFace.ComputeNormal(new UV(0,0));



            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;

            List <XYZ> myEndPoints = getPointCenterTopLine(myBeam);

            XYZ p1 = myEndPoints[0];
            XYZ p2 = myEndPoints[1];


            Line centerLineBeam = Line.CreateBound(p1, p2);



            XYZ p = centerLineBeam.GetEndPoint(0);
            XYZ q = centerLineBeam.GetEndPoint(1);
            XYZ v = p - q;


            XYZ v1 = new XYZ(v.Y, -1 * v.X, v.Z);


            XYZ p1_Rb = new XYZ(p1.X, p1.Y, p1.Z - 25 / 304.8);
            XYZ p2_Rb = new XYZ(p2.X, p2.Y, p2.Z - 25 / 304.8);

            Line curveOfRebar = Line.CreateBound(p1, p2);


            List <Curve> myShape = new List <Curve>()
            {
                curveOfRebar
            };


            // Rebartype
            FilteredElementCollector fec1 = new FilteredElementCollector(doc)
                                            .OfClass(typeof(RebarBarType));


            IEnumerable <RebarBarType> iterRebarBarTypes = fec1.Cast <RebarBarType>();

            RebarBarType myRebarType = iterRebarBarTypes.First();


            // Hooktype
            FilteredElementCollector fec2 = new FilteredElementCollector(doc)
                                            .OfClass(typeof(RebarHookType));


            IEnumerable <RebarHookType> iterRebarHookTypes = fec2.Cast <RebarHookType>();

            RebarHookType myRebarHookType = iterRebarHookTypes.First();

            using (Transaction trans = new Transaction(doc, "rebar test"))

            {
                trans.Start();
                Rebar myRebar = Rebar.CreateFromCurves(doc, RebarStyle.Standard, myRebarType,
                                                       myRebarHookType,
                                                       myRebarHookType, myBeam,
                                                       v1, myShape,
                                                       RebarHookOrientation.Left, RebarHookOrientation.Left,
                                                       true, false);

                trans.Commit();
            }
        }
Ejemplo n.º 9
0
        //private void setBeJoined(Document doc, Element myBeJoined)
        //{

        //    ICollection<ElementId> myListElemIdsJoined = JoinGeometryUtils.GetJoinedElements(doc, myBeJoined);

        //    using (Transaction trans = new Transaction(doc, "Switch Join"))
        //    {
        //        trans.Start();
        //        foreach (ElementId myElemId in myListElemIdsJoined)
        //        {

        //            if (!JoinGeometryUtils.IsCuttingElementInJoin(doc, doc.GetElement(myElemId), myBeJoined))
        //            {
        //                JoinGeometryUtils.SwitchJoinOrder(doc, doc.GetElement(myElemId), myBeJoined);
        //            }

        //        }

        //        trans.Commit();
        //    }
        //}


        public void Rebar_FromCurve_Top_Func(Document doc, Element myBeam, List <Face> myListFacePicked, double divideFac, double coverBar,
                                             string myRebarShapeName, string myRebarTypeName)
        {
            //BoundingBox beam
            BoundingBoxXYZ myBoundBeam = myBeam.get_BoundingBox(null);
            double         hBeam       = myBoundBeam.Max.Z - myBoundBeam.Min.Z;

            LocationCurve myLocBeam = myBeam.Location as LocationCurve;

            Line myLocLine = myLocBeam.Curve as Line;

            XYZ p = myLocLine.GetEndPoint(0);
            XYZ q = myLocLine.GetEndPoint(1);

            XYZ v = q - p;

            XYZ pE = p - 0.5 * v;
            XYZ vE = q - pE;

            XYZ vRB = new XYZ(v.Y, -1 * v.X, v.Z);

            List <double> myListDisSortFace = getAndSortDisOfEndFaces(myListFacePicked, pE);


            double lengSeg_1 = myListDisSortFace[1] - myListDisSortFace[0];
            double lengSeg_2 = myListDisSortFace[3] - myListDisSortFace[2];

            XYZ ePR1_XY = pE + ((myListDisSortFace[1] - lengSeg_1 / divideFac) / vE.GetLength()) * vE;
            XYZ ePR2_XY = pE + ((myListDisSortFace[2] + lengSeg_2 / divideFac) / vE.GetLength()) * vE;


            XYZ ePR1 = new XYZ(ePR1_XY.X, ePR1_XY.Y, myBoundBeam.Max.Z - coverBar);
            XYZ ePR2 = new XYZ(ePR2_XY.X, ePR2_XY.Y, myBoundBeam.Max.Z - coverBar);

            Line curveOfRebar = Line.CreateBound(ePR1, ePR2);

            //Tang
            List <Curve> myShape = new List <Curve>()
            {
                curveOfRebar
            };

            // RebarShape
            FilteredElementCollector fecRebarShape = new FilteredElementCollector(doc)
                                                     .OfClass(typeof(RebarShape));

            RebarShape myRebarShape = fecRebarShape.Cast <RebarShape>().
                                      First <RebarShape>(myRebarShape2 => myRebarShape2.Name == myRebarShapeName);


            // Rebartype
            FilteredElementCollector fecRebarType = new FilteredElementCollector(doc)
                                                    .OfClass(typeof(RebarBarType));
            RebarBarType myRebarType = fecRebarType.Cast <RebarBarType>().
                                       First <RebarBarType>(myRebarType2 => myRebarType2.Name == myRebarTypeName);



            // Hooktype
            FilteredElementCollector fec2 = new FilteredElementCollector(doc)
                                            .OfClass(typeof(RebarHookType));

            IEnumerable <RebarHookType> iterRebarHookTypes = fec2.Cast <RebarHookType>();

            RebarHookType myRebarHookType = iterRebarHookTypes.First();

            using (Transaction trans = new Transaction(doc, "rebar test"))

            {
                trans.Start();
                Rebar myRebar = Rebar.CreateFromCurves(doc, RebarStyle.Standard, myRebarType,
                                                       null, null,
                                                       myBeam, vRB,
                                                       myShape,
                                                       RebarHookOrientation.Left, RebarHookOrientation.Right,
                                                       true, false);


                trans.Commit();
            }
        }