예제 #1
0
        /// <summary>
        /// Add stirrup bars into corbel with given options.
        /// </summary>
        /// <param name="options">Options for Rebar Creation</param>
        private void PlaceStirrupBars(CorbelReinforcementOptions options)
        {
            var filter = new FilteredElementCollector(options.RevitDoc)
                         .OfClass(typeof(RebarShape)).ToElements().Cast <RebarShape>()
                         .Where <RebarShape>(shape => shape.RebarStyle == RebarStyle.StirrupTie);

            RebarShape stirrupShape = null;

            foreach (RebarShape shape in filter)
            {
                if (shape.Name.Equals("T1"))
                {
                    stirrupShape = shape; break;
                }
            }

            Trapezoid profileCopy = m_profile.Clone();

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

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

            XYZ origin = profileCopy.Vertical.GetEndPoint(0) + extruDir * offset;
            XYZ xAxis  = extruDir;
            XYZ yAxis  = (profileCopy.Vertical.GetEndPoint(1) - profileCopy.Vertical.GetEndPoint(0)).Normalize();

            Rebar stirrupBars = Rebar.CreateFromRebarShape(options.RevitDoc, stirrupShape,
                                                           options.StirrupBarType, m_corbel, origin, xAxis, yAxis);

            double xLength = m_extrusionLine.Length - 2 * offset;
            double yLength = profileCopy.Vertical.Length;

            stirrupBars.GetShapeDrivenAccessor().SetLayoutAsFixedNumber(options.StirrupBarCount + 1, profileCopy.Top.Length, false, false, true);
            stirrupBars.GetShapeDrivenAccessor().ScaleToBox(origin, xAxis * xLength, yAxis * yLength);
            ShowRebar3d(stirrupBars);

            double space = profileCopy.Top.Length / options.StirrupBarCount;
            double step  = space * m_profile.Vertical.Length / (m_profile.Bottom.Length - m_profile.Top.Length);

            XYZ dirTop      = (m_profile.Top.GetEndPoint(0) - m_profile.Top.GetEndPoint(1)).Normalize();
            XYZ dirVertical = yAxis;
            XYZ deltaStep   = dirTop * space + dirVertical * step;

            origin = profileCopy.Top.GetEndPoint(0) + extruDir * offset;
            int count = (int)((m_profile.Vertical.Length - m_corbelCoverDistance - 0.5 * options.StirrupBarType.BarDiameter) / step);

            for (int i = 1; i <= count; i++)
            {
                origin += deltaStep;
                Rebar stirrupBars2 = Rebar.CreateFromRebarShape(options.RevitDoc, stirrupShape,
                                                                options.StirrupBarType, m_corbel, origin, xAxis, yAxis);

                stirrupBars2.GetShapeDrivenAccessor().ScaleToBox(origin, xAxis * xLength, yAxis * (yLength - i * step));
                ShowRebar3d(stirrupBars2);
            }
        }
예제 #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.GetShapeDrivenAccessor().SetLayoutAsFixedNumber(2, m_extrusionLine.Length - 2 * offset, true, true, true);

            ShowRebar3d(bars);
        }
예제 #3
0
 /// <summary>
 /// Gets bar position transform.
 /// </summary>
 /// <param name="element">The rebar element.</param>
 /// <param name="barPositionIndex">The bar position.</param>
 /// <returns>The transform.</returns>
 static Transform GetBarPositionTransform(object element, int barPositionIndex)
 {
     if (element is Rebar)
     {
         Rebar     rebar             = element as Rebar;
         Transform movedBarTransform = rebar.GetMovedBarTransform(barPositionIndex);
         if (rebar.IsRebarFreeForm())
         {
             return(movedBarTransform);
         }
         else
         {
             // shape driven
             Transform barPosTrf = rebar.GetShapeDrivenAccessor().GetBarPositionTransform(barPositionIndex);
             Transform entireTrf = movedBarTransform.Multiply(barPosTrf);
             return(entireTrf);
         }
     }
     else if (element is RebarInSystem)
     {
         RebarInSystem rebarInSystem = element as RebarInSystem;
         Transform     barPosTrf     = rebarInSystem.GetBarPositionTransform(barPositionIndex);
         Transform     movedBarTrf   = rebarInSystem.GetMovedBarTransform(barPositionIndex);
         Transform     entireTrf     = movedBarTrf.Multiply(barPosTrf);
         return(entireTrf);
     }
     else if (element is RebarContainerItem)
     {
         return((element as RebarContainerItem).GetBarPositionTransform(barPositionIndex));
     }
     else
     {
         throw new ArgumentException("Not a rebar.");
     }
 }
예제 #4
0
        /// <summary>
        /// Move and Scale the  created Rebar to specified box.
        /// </summary>
        private void LayoutRebar()
        {
            List <Autodesk.Revit.DB.XYZ> profilePoints = m_geometryData.OffsetPoints(0.1);

            Autodesk.Revit.DB.XYZ origin = profilePoints[0];
            Autodesk.Revit.DB.XYZ yVec   = profilePoints[1] - origin;
            Autodesk.Revit.DB.XYZ xVec   = profilePoints[3] - origin;

            RebarShapeDefinitionByArc arcDef =
                (m_createdRebar.Document.GetElement(m_createdRebar.GetShapeId()) as RebarShape).GetRebarShapeDefinition() as RebarShapeDefinitionByArc;

            RebarShapeDrivenAccessor rebarShapeDrivenAccessor = m_createdRebar.GetShapeDrivenAccessor();

            if (arcDef != null && arcDef.Type == RebarShapeDefinitionByArcType.Spiral)
            {
                rebarShapeDrivenAccessor.ScaleToBoxFor3D(origin, xVec, yVec, 10.0);
                rebarShapeDrivenAccessor.Height             = m_geometryData.DrivingLength - 0.1;
                rebarShapeDrivenAccessor.Pitch              = 0.1;
                rebarShapeDrivenAccessor.BaseFinishingTurns = 3;
                rebarShapeDrivenAccessor.TopFinishingTurns  = 3;
            }
            else
            {
                rebarShapeDrivenAccessor.ScaleToBox(origin, xVec, yVec);
                double barSpacing = 0.1;
                int    barNum     = (int)(m_geometryData.DrivingLength / barSpacing);
                rebarShapeDrivenAccessor.SetLayoutAsNumberWithSpacing(
                    barNum, barSpacing, true, true, true);
            }
        }
예제 #5
0
        /// <summary>
        /// The helper function to changed rebar number and spacing properties
        /// </summary>
        /// <param name="bar">The rebar instance which need to modify</param>
        /// <param name="number">The rebar number want to set</param>
        /// <param name="spacing">The spacing want to set</param>
        protected static void SetRebarSpaceAndNumber(Rebar bar, int number, double spacing)
        {
            // Asset the parameter is valid
            if (null == bar || 2 > number || 0 > spacing)
            {
                return;
            }

            // Change the rebar number and spacing properties
            bar.GetShapeDrivenAccessor().SetLayoutAsNumberWithSpacing(number, spacing, true, true, true);
        }
예제 #6
0
 /// <summary>
 /// Get Transformed Centerline curves at position.
 /// This method extracts the centerlinecurves for a rebar set at a given index and transforms them to the correct position.
 /// </summary>
 /// <param name="rebar"></param>
 /// <param name="barPosIndex"></param>
 /// <returns></returns>
 public static IList<Curve> GetTransformedCenterLineCurvesAtPostition(Rebar rebar, int barPosIndex)
 {
     RebarShapeDrivenAccessor sda = rebar.GetShapeDrivenAccessor();
     Transform transform = sda.GetBarPositionTransform(barPosIndex);
     IList<Curve> curves = rebar.GetCenterlineCurves(false, false, false, MultiplanarOption.IncludeOnlyPlanarCurves, barPosIndex);
     IList<Curve> transformedCurves = new List<Curve>();
     foreach (Curve curve in curves)
     {
         transformedCurves.Add(curve.CreateTransformed(transform));
     }
     return transformedCurves;
 }
예제 #7
0
        /// <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.GetShapeDrivenAccessor().ScaleToBoxFor3D(origin + extruDir * (m_extrusionLine.Length - offset),
                                                              vx, vy, m_extrusionLine.Length - 2 * offset);
            ShowRebar3d(newRebar);
        }
예제 #8
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.GetShapeDrivenAccessor().SetLayoutAsFixedNumber(options.TopBarCount + 2,
                                                                 m_extrusionLine.Length - 2 * offset, true, false, false);
            ShowRebar3d(bars);
        }
예제 #9
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);
        }
예제 #10
0
        // Select Faces boundaries

        public void rebarBeam_Form_Update()
        {
            UIDocument uiDoc = this.ActiveUIDocument;
            Document   doc   = uiDoc.Document;

            double factor  = 4;
            double delta_1 = 50 / 304.8;
            double pitch_1 = 150 / 304.8;
            double pitch_2 = 300 / 304.8;

            double delta_3 = 50 / 304.8;
            double pitch_3 = 100 / 304.8;
            int    N3      = 5;

            double myConvertFactor = 304.8;


            bool inputSuccess = false;

            while (!inputSuccess)
            {
                using (var myInputFormSetting = new InputDialog())
                {
                    myInputFormSetting.ShowDialog();

                    factor  = Convert.ToDouble(myInputFormSetting.factorTb.Text);
                    delta_1 = Convert.ToDouble(myInputFormSetting.delta_1Tb.Text) / myConvertFactor;
                    pitch_1 = Convert.ToDouble(myInputFormSetting.pitch_1Tb.Text) / myConvertFactor;
                    pitch_2 = Convert.ToDouble(myInputFormSetting.pitch_2Tb.Text) / myConvertFactor;

                    delta_3 = Convert.ToDouble(myInputFormSetting.delta_3Tb.Text) / myConvertFactor;
                    pitch_3 = Convert.ToDouble(myInputFormSetting.pitch_3Tb.Text) / myConvertFactor;
                    N3      = Convert.ToInt32(myInputFormSetting.n3Tb.Text);


                    //if the user hits cancel just drop out of macro
                    if (myInputFormSetting.DialogResult == System.Windows.Forms.DialogResult.Cancel)
                    {
                        return;
                    }
                    {
                        //else do all this :)
                        myInputFormSetting.Close();
                    }

                    if (myInputFormSetting.DialogResult == System.Windows.Forms.DialogResult.OK)
                    {
                        //else do all this :)
                        inputSuccess = true;
                        myInputFormSetting.Close();
                    }
                }
            }


            // Pick Rebar
            List <int> myListIdCategoryRebar = new List <int>();

            myListIdCategoryRebar.Add((int)BuiltInCategory.OST_Rebar);

            // Select first Element (ex beam)
            Reference myRefRebar = uiDoc.Selection.PickObject(ObjectType.Element,
                                                              new FilterByIdCategory(myListIdCategoryRebar),
                                                              "Pick a Rebar...");
            //Get rebar from ref
            Rebar myRebar = doc.GetElement(myRefRebar) as Rebar;

            //Set rebar single
            //			using (Transaction myTrans = new Transaction(doc,"SET FIRST REBAR AS SINGLE"))
            //
            //			{
            //				myTrans.Start();
            //				myRebar.GetShapeDrivenAccessor().SetLayoutAsSingle();
            //				myTrans.Commit();
            //			}


            Element myBeam = doc.GetElement(myRebar.GetHostId());

            //Get location curve of beam
            LocationCurve lc   = myBeam.Location as LocationCurve;
            Line          line = lc.Curve as Line;

            //Get vector of location cuver beam
            XYZ p1 = line.GetEndPoint(0);
            XYZ q  = line.GetEndPoint(1);
            XYZ v  = q - p1; // Vector equation of line

            XYZ p = p1 - 0.1 * v;

            //Set current Beam be Joined

            setBeJoined(myBeam);

            while (true)
            {
                //Pick Face end

                List <Reference> myListRef = uiDoc.Selection.PickObjects(ObjectType.Face) as List <Reference>;

                List <Face> myListFacePicked = new List <Face>();

                foreach (Reference myRef in myListRef)
                {
                    Element E = doc.GetElement(myRef);

                    GeometryObject myGeoObj = E.GetGeometryObjectFromReference(myRef);

                    Face myPickedFace = myGeoObj as Face;

                    myListFacePicked.Add(myPickedFace);
                }

                if (myListFacePicked.Count != 2 && myListFacePicked.Count != 4)
                {
                    TaskDialog.Show("Error!", "Chua ho tro lua chon: " + myListFacePicked.Count() + " mat, Chon 2 hoac 4 mat");
                    continue;
                }

                else
                {
                    string caseDistributionRebar = "TH2: Co dam o giua";

                    List <double> myListSpace = new List <double>()
                    {
                        pitch_1, pitch_2, pitch_3, pitch_3, pitch_2, pitch_1
                    };
                    if (myListFacePicked.Count == 2)
                    {
                        myListSpace = new List <double>()
                        {
                            pitch_1, pitch_2, pitch_1, pitch_2, pitch_2, pitch_1
                        };
                        caseDistributionRebar = "TH1: Khong co dam o giua";
                    }
                    TaskDialog.Show("Info", caseDistributionRebar);

                    // List of boundaries faces
                    List <double> myListEndPointDis = getAndSortDisOfEndFaces(myListFacePicked, p);
                    myListEndPointDis.Sort();



                    Dictionary <double, int> myDicDisNumDetail = detailListDistance_Update(myListEndPointDis,
                                                                                           factor,
                                                                                           delta_1, pitch_1,
                                                                                           pitch_2,
                                                                                           delta_3, pitch_3, N3);


                    List <ElementId> myListRebarCopyId = copyRebarByDistance2_Update(myRebar, myDicDisNumDetail);


                    List <double> myDistances = myDicDisNumDetail.Keys.ToList();
                    myDistances.Sort();



                    List <int> myListNum = new List <int>();

                    foreach (double key in myDistances)
                    {
                        myListNum.Add(myDicDisNumDetail[key]);
                    }

                    //Layout

                    // using transcation (edit DB)
                    for (int i = 0; i < myListRebarCopyId.Count(); i++)
                    {
                        using (Transaction myTrans = new Transaction(doc, "CopyElementByCoordinate"))

                        {
                            myTrans.Start();
                            ElementId rebarId  = myListRebarCopyId[i];
                            Rebar     myRebarI = doc.GetElement(rebarId) as Rebar;

                            if (myListNum[i] < -1)
                            {
                                myRebarI.GetShapeDrivenAccessor().SetLayoutAsNumberWithSpacing((myListNum[i]) * -1, myListSpace[i], true, true, true);
                            }

                            if (myListNum[i] == -1)
                            {
                                myRebarI.GetShapeDrivenAccessor().SetLayoutAsSingle();
                            }

                            if (myListNum[i] == 0)
                            {
                                myRebarI.GetShapeDrivenAccessor().SetLayoutAsSingle();
                            }

                            if (myListNum[i] == 1)
                            {
                                myRebarI.GetShapeDrivenAccessor().SetLayoutAsSingle();
                            }

                            if (myListNum[i] > 1)
                            {
                                myRebarI.GetShapeDrivenAccessor().SetLayoutAsNumberWithSpacing(myListNum[i], myListSpace[i], false, true, true);
                            }
                            myTrans.Commit();
                        }
                    }

                    //delete element
                    using (Transaction myTrans = new Transaction(doc, "Delete First ReBar"))

                    {
                        myTrans.Start();
                        //doc.Delete(myRebar.Id);
                        myTrans.Commit();
                    }
                }
            }
        }
예제 #11
0
        public void rebarBeam2Col(Document doc, double factor, double delta_1, double pitch_1, double pitch_2, Rebar myRebar, List <Element> myInterSec)
        {
            //UIDocument uiDoc = this.ActiveUIDocument;
            //Document doc = uiDoc.Document;


            // Get baem Id
            ElementId myBeamId = myRebar.GetHostId();

            double        lenSegment;
            List <double> myListDis = new List <double>();


            ElementId myCol1Id = myInterSec[0].Id;
            ElementId myCol2Id = myInterSec[1].Id;


            myListDis  = getEndsSegBeam(doc, myBeamId, myCol1Id, myCol2Id);
            lenSegment = myListDis[1] - myListDis[0];



            List <double> myListDisDetail = detailListDistance(myListDis, factor, delta_1, pitch_1);


            List <ElementId> myListRebarCopyId = copyRebarByDistance(doc, myRebar, myListDisDetail);

            // RebarSet Layout


            using (Transaction trans = new Transaction(doc, "Change rebar set"))
            {
                trans.Start();

                for (int i = 0; i < myListRebarCopyId.Count; i++)
                {
                    ElementId rebarId = myListRebarCopyId[i];

                    Rebar myRebarI = doc.GetElement(rebarId) as Rebar;

                    int numberRebar = 2;

                    if (i == myListRebarCopyId.Count - 1)
                    {
                        numberRebar = (int)((lenSegment / factor) / pitch_1);

                        myRebarI.GetShapeDrivenAccessor().SetLayoutAsNumberWithSpacing(numberRebar, pitch_1, true, true, true);
                    }

                    else if (i == 0)
                    {
                        numberRebar = (int)((lenSegment / factor) / pitch_1);
                        myRebarI.GetShapeDrivenAccessor().SetLayoutAsNumberWithSpacing(numberRebar, pitch_1, false, true, true);
                    }

                    else if (i == 1)
                    {
                        double delta_2 = (lenSegment / factor - delta_1) % pitch_1;
                        double len2    = (lenSegment - 2 * (lenSegment / factor) + delta_2);

                        numberRebar = (int)((lenSegment - 2 * (lenSegment / factor) + delta_2) / pitch_2) + 1;
                        myRebarI.GetShapeDrivenAccessor().SetLayoutAsNumberWithSpacing(numberRebar, pitch_2, false, true, true);
                    }
                }

                trans.Commit();
            }
        }
예제 #12
0
        public void rebarStirrupLayout_Form(UIDocument uiDoc)
        {
            Document doc = uiDoc.Document;

            double factor  = 4;
            double delta_1 = 50 / 304.8;
            double pitch_1 = 150 / 304.8;
            double pitch_2 = 300 / 304.8;

            double delta_3 = 50 / 304.8;
            double pitch_3 = 100 / 304.8;
            int    N3      = 5;

            double myConvertFactor = 304.8;


            bool inputSuccess = false;

            while (!inputSuccess)
            {
                using (var myInputFormSetting = new SettingDialog())
                {
                    myInputFormSetting.ShowDialog();

                    factor  = Convert.ToDouble(myInputFormSetting.factorTb.Text);
                    delta_1 = Convert.ToDouble(myInputFormSetting.delta_1Tb.Text) / myConvertFactor;
                    pitch_1 = Convert.ToDouble(myInputFormSetting.pitch_1Tb.Text) / myConvertFactor;
                    pitch_2 = Convert.ToDouble(myInputFormSetting.pitch_2Tb.Text) / myConvertFactor;

                    delta_3 = Convert.ToDouble(myInputFormSetting.delta_3Tb.Text) / myConvertFactor;
                    pitch_3 = Convert.ToDouble(myInputFormSetting.pitch_3Tb.Text) / myConvertFactor;
                    N3      = Convert.ToInt32(myInputFormSetting.n3Tb.Text);


                    //if the user hits cancel just drop out of macro
                    if (myInputFormSetting.DialogResult == System.Windows.Forms.DialogResult.Cancel)
                    {
                        return;
                    }
                    {
                        //else do all this :)
                        myInputFormSetting.Close();
                    }

                    if (myInputFormSetting.DialogResult == System.Windows.Forms.DialogResult.OK)
                    {
                        //else do all this :)
                        inputSuccess = true;
                        myInputFormSetting.Close();
                    }
                }
            }


            // Pick Rebar
            List <int> myListIdCategoryRebar = new List <int>();

            myListIdCategoryRebar.Add((int)BuiltInCategory.OST_Rebar);

            // Select first Element (ex beam)
            Reference myRefRebar = uiDoc.Selection.PickObject(ObjectType.Element,
                                                              new FilterByIdCategory(myListIdCategoryRebar),
                                                              "Pick a Rebar...");
            //Get rebar from ref
            Rebar myRebar = doc.GetElement(myRefRebar) as Rebar;

            //Set rebar single

            using (Transaction myTrans = new Transaction(doc, "SET FIRST REBAR AS SINGLE"))

            {
                myTrans.Start();
                myRebar.GetShapeDrivenAccessor().SetLayoutAsSingle();
                myTrans.Commit();
            }


            Element myBeam = doc.GetElement(myRebar.GetHostId());

            //Set current Beam be Joined

            setBeJoined(doc, myBeam);

            while (true)
            {
                List <int> myListBeamCol = new List <int>();
                myListBeamCol.Add((int)BuiltInCategory.OST_StructuralFraming);
                myListBeamCol.Add((int)BuiltInCategory.OST_StructuralColumns);
                // Select first Element (ex beam)
                List <Reference> myListInterRef = uiDoc.Selection.PickObjects(ObjectType.Element,
                                                                              new FilterByIdCategory(myListBeamCol),
                                                                              "Pick a Beam and Col...") as List <Reference>;

                List <Element> myInterSec = new List <Element>();


                foreach (Reference myRef in myListInterRef)
                {
                    myInterSec.Add(doc.GetElement(myRef));
                }

                // Kiem tra co 2 cot ko?
                int numCol = 0;

                foreach (Element myE in myInterSec)
                {
                    if (myE.Category.Name == "Structural Columns")
                    {
                        numCol += 1;
                    }
                }

                if (numCol != 2 || myInterSec.Count > 3)
                {
                    TaskDialog.Show("Erorr!!!", "Các đối tượng được chọn phải có đủ 2 cột và tối đa 1 dầm");
                    //return;
                }

                // Kiem tra truong hop tinh
                if (myInterSec.Count() == 2)
                {
                    rebarBeam2Col(doc, factor, delta_1, pitch_1, pitch_2, myRebar, myInterSec);
                }

                else
                {
                    List <double> myListEndPointDis = getEndsSegBeam2(doc, myBeam.Id, myInterSec);
                    myListEndPointDis.Sort();


                    Dictionary <double, int> myDicDisNumDetail = detailListDistance2(myListEndPointDis,
                                                                                     factor,
                                                                                     delta_1, pitch_1,
                                                                                     pitch_2,
                                                                                     delta_3, pitch_3, N3);


                    List <double> myListSpace = new List <double>()
                    {
                        pitch_1, pitch_2, pitch_3, pitch_3, pitch_2, pitch_1
                    };

                    List <ElementId> myListRebarCopyId = copyRebarByDistance2(doc, myRebar, myDicDisNumDetail);


                    List <double> myDistances = myDicDisNumDetail.Keys.ToList();
                    myDistances.Sort();



                    List <int> myListNum = new List <int>();

                    foreach (double key in myDistances)
                    {
                        myListNum.Add(myDicDisNumDetail[key]);
                    }

                    //Layout

                    // using transcation (edit DB)
                    for (int i = 0; i < myListRebarCopyId.Count(); i++)
                    {
                        using (Transaction myTrans = new Transaction(doc, "CopyElementByCoordinate"))

                        {
                            myTrans.Start();
                            ElementId rebarId  = myListRebarCopyId[i];
                            Rebar     myRebarI = doc.GetElement(rebarId) as Rebar;

                            if (myListNum[i] < -1)
                            {
                                myRebarI.GetShapeDrivenAccessor().SetLayoutAsNumberWithSpacing((myListNum[i]) * -1, myListSpace[i], true, true, true);
                            }

                            if (myListNum[i] == -1)
                            {
                                myRebarI.GetShapeDrivenAccessor().SetLayoutAsSingle();
                            }

                            if (myListNum[i] == 0)
                            {
                                myRebarI.GetShapeDrivenAccessor().SetLayoutAsSingle();
                            }

                            if (myListNum[i] == 1)
                            {
                                myRebarI.GetShapeDrivenAccessor().SetLayoutAsSingle();
                            }

                            if (myListNum[i] > 1)
                            {
                                myRebarI.GetShapeDrivenAccessor().SetLayoutAsNumberWithSpacing(myListNum[i], myListSpace[i], false, true, true);
                            }
                            myTrans.Commit();
                        }
                    }

                    //delete element
                    using (Transaction myTrans = new Transaction(doc, "Delete First ReBar"))

                    {
                        myTrans.Start();
                        //doc.Delete(myRebar.Id);
                        myTrans.Commit();
                    }
                }
            }
        }
        public void rebarStirrupLayout_Form(UIDocument uiDoc)
        {
            Document doc = uiDoc.Document;

            //Stirrup
            bool isSt1Yes   = true;
            bool isOpposite = false;

            double factor  = 4;
            double delta_1 = 50 / 304.8;
            double pitch_1 = 150 / 304.8;
            double pitch_2 = 300 / 304.8;

            double delta_3 = 50 / 304.8;
            double pitch_3 = 100 / 304.8;
            int    N3      = 4;


            //Stirrup
            bool isYes_C1      = true;
            bool isOpposite_C1 = false;

            double factor_C1  = 4;
            double delta_1_C1 = 50 / 304.8;
            double pitch_1_C1 = 150 / 304.8;
            double pitch_2_C1 = 300 / 304.8;

            double delta_3_C1 = 50 / 304.8;
            double pitch_3_C1 = 100 / 304.8;
            int    N3_C1      = 4;

            double myConvertFactor = 304.8;


            //Load rebarShape
            // RebarShape
            FilteredElementCollector fecRebarShap = new FilteredElementCollector(doc)
                                                    .OfClass(typeof(RebarShape));

            IEnumerable <RebarShape> iterRebarBarShapes = fecRebarShap.Cast <RebarShape>();


            // Load Rebar Type
            // Rebartype
            FilteredElementCollector fecBarType = new FilteredElementCollector(doc)
                                                  .OfClass(typeof(RebarBarType));

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


            // Bottom Layer
            // Layer1
            bool   isLB1Yes         = true;
            double FB1              = 6;
            double CB1              = 80;
            string rebaNameShape_L1 = string.Empty;
            string rebaNameType_L1  = string.Empty;


            // Bottom Layer
            // Layer2
            bool   isLB2Yes = true;
            double FB2      = 3;
            double CB2      = 150;

            string rebaNameShape_L2 = string.Empty;
            string rebaNameType_L2  = string.Empty;

            bool inputSuccess = false;

            while (!inputSuccess)
            {
                using (var myInputFormSetting = new SettingDialog())
                {
                    //add rebar Shape list
                    foreach (RebarShape myRebarShape in iterRebarBarShapes)
                    {
                        myInputFormSetting.RebarShap1_Cb.Items.Add(myRebarShape.Name);
                        myInputFormSetting.RebarShap2_Cb.Items.Add(myRebarShape.Name);
                    }

                    //					myInputFormSetting.RebarShap1_Cb.SelectedIndex = 0;
                    //					myInputFormSetting.RebarShap2_Cb.SelectedIndex = 0;

                    //add rebar type list
                    foreach (RebarBarType myRebarType in iterRebarBarTypes)
                    {
                        myInputFormSetting.RebarType1_Cb.Items.Add(myRebarType.Name);
                        myInputFormSetting.RebarType2_Cb.Items.Add(myRebarType.Name);
                    }

                    //					myInputFormSetting.RebarType1_Cb.SelectedIndex = 1;
                    //					myInputFormSetting.RebarType2_Cb.SelectedIndex = 1;


                    myInputFormSetting.ShowDialog();

                    //stirrup
                    factor  = Convert.ToDouble(myInputFormSetting.factorTb.Text);
                    delta_1 = Convert.ToDouble(myInputFormSetting.delta_1Tb.Text) / myConvertFactor;
                    pitch_1 = Convert.ToDouble(myInputFormSetting.pitch_1Tb.Text) / myConvertFactor;
                    pitch_2 = Convert.ToDouble(myInputFormSetting.pitch_2Tb.Text) / myConvertFactor;

                    delta_3    = Convert.ToDouble(myInputFormSetting.delta_3Tb.Text) / myConvertFactor;
                    pitch_3    = Convert.ToDouble(myInputFormSetting.pitch_3Tb.Text) / myConvertFactor;
                    N3         = Convert.ToInt32(myInputFormSetting.n3Tb.Text);
                    isOpposite = myInputFormSetting.oppDirChecked;
                    isSt1Yes   = myInputFormSetting.yesST_Chb.Checked;


                    //C1
                    factor_C1  = Convert.ToDouble(myInputFormSetting.factor_C1Tb.Text);
                    delta_1_C1 = Convert.ToDouble(myInputFormSetting.delta_1_C1Tb.Text) / myConvertFactor;
                    pitch_1_C1 = Convert.ToDouble(myInputFormSetting.pitch_1_C1Tb.Text) / myConvertFactor;
                    pitch_2_C1 = Convert.ToDouble(myInputFormSetting.pitch_2_C1Tb.Text) / myConvertFactor;

                    delta_3_C1    = Convert.ToDouble(myInputFormSetting.delta_3_C1Tb.Text) / myConvertFactor;
                    pitch_3_C1    = Convert.ToDouble(myInputFormSetting.pitch_3_C1Tb.Text) / myConvertFactor;
                    N3_C1         = Convert.ToInt32(myInputFormSetting.n3_C1Tb.Text);
                    isOpposite_C1 = myInputFormSetting.oppDirChecked;
                    isYes_C1      = myInputFormSetting.yesC1_Chb.Checked;


                    //Shape
                    rebaNameShape_L1 = myInputFormSetting.RebarShap1_Cb.Text;
                    rebaNameShape_L2 = myInputFormSetting.RebarShap2_Cb.Text;

                    //type
                    rebaNameType_L1 = myInputFormSetting.RebarType1_Cb.Text;
                    rebaNameType_L2 = myInputFormSetting.RebarType2_Cb.Text;


                    //Yes/ No bottom rebar
                    if (!myInputFormSetting.yes1_Chb.Checked)
                    {
                        isLB1Yes = false;
                    }
                    if (!myInputFormSetting.yes2_Chb.Checked)
                    {
                        isLB2Yes = false;
                    }

                    // Layer1

                    FB1 = Convert.ToDouble(myInputFormSetting.FB1_Tb.Text);
                    CB1 = Convert.ToDouble(myInputFormSetting.CB1_Tb.Text) / myConvertFactor;


                    // Bottom Layer
                    // Layer2

                    FB2 = Convert.ToDouble(myInputFormSetting.FB2_Tb.Text);
                    CB2 = Convert.ToDouble(myInputFormSetting.CB2_Tb.Text) / myConvertFactor;



                    //if the user hits cancel just drop out of macro
                    if (myInputFormSetting.DialogResult == System.Windows.Forms.DialogResult.Cancel)
                    {
                        return;
                    }
                    {
                        //else do all this :)
                        myInputFormSetting.Close();
                    }

                    if (myInputFormSetting.DialogResult == System.Windows.Forms.DialogResult.OK)
                    {
                        //else do all this :)
                        inputSuccess = true;
                        myInputFormSetting.Close();
                    }
                }
            }

            //Check mode
            //			TaskDialog.Show("opposite", isOpposite.ToString());
            //			TaskDialog.Show("draw stirrup", isSt1Yes.ToString());
            //
            //			TaskDialog.Show("isL1", isLB1Yes.ToString());
            //			TaskDialog.Show("IsL2", isLB1Yes.ToString());
            //
            //
            //
            //			TaskDialog.Show("Rebar Shape1", rebaNameShape_L1);
            //			TaskDialog.Show("Rebar Shape2", rebaNameShape_L2);
            //
            //
            //			TaskDialog.Show("Rebar Shape1", rebaNameType_L1);
            //			TaskDialog.Show("Rebar Shape2", rebaNameType_L2);


            //Set mybeam
            Element myBeam = null;

            // Kiem tra ve stirrup

            List <Rebar> myListRebar    = new List <Rebar>();
            List <Rebar> myListRebar_C1 = new List <Rebar>();

            if (isSt1Yes)
            {
                // Pick Rebar
                List <int> myListIdCategoryRebar = new List <int>();
                myListIdCategoryRebar.Add((int)BuiltInCategory.OST_Rebar);

                // Select first Element (ex beam)
                List <Reference> myListRefRebar = uiDoc.Selection.PickObjects(ObjectType.Element,
                                                                              new FilterByIdCategory(myListIdCategoryRebar),
                                                                              "Pick a stirrup Rebar...") as List <Reference>;


                foreach (Reference myRefRebar in myListRefRebar)
                {
                    Rebar myRebarpicked = doc.GetElement(myRefRebar) as Rebar;
                    myListRebar.Add(myRebarpicked);
                }
                myBeam = doc.GetElement(myListRebar[0].GetHostId());
            }

            if (isYes_C1)
            {
                // Pick Rebar
                List <int> myListIdCategoryRebar_C1 = new List <int>();
                myListIdCategoryRebar_C1.Add((int)BuiltInCategory.OST_Rebar);

                // Select first Element (ex beam)
                List <Reference> myListRefRebar_C1 = uiDoc.Selection.PickObjects(ObjectType.Element,
                                                                                 new FilterByIdCategory(myListIdCategoryRebar_C1),
                                                                                 "Pick a C Rebar ...") as List <Reference>;


                foreach (Reference myRefRebar_C1 in myListRefRebar_C1)
                {
                    Rebar myRebarpicked_C1 = doc.GetElement(myRefRebar_C1) as Rebar;
                    myListRebar_C1.Add(myRebarpicked_C1);
                }
                myBeam = doc.GetElement(myListRebar_C1[0].GetHostId());
            }

            else
            {
                List <int> myListIdCategoryRebar = new List <int>();
                myListIdCategoryRebar.Add((int)BuiltInCategory.OST_StructuralFraming);
                Reference myRefmyBeam = uiDoc.Selection.PickObject(ObjectType.Element,
                                                                   new FilterByIdCategory(myListIdCategoryRebar),
                                                                   "Pick a Beam...");

                myBeam = doc.GetElement(myRefmyBeam);
            }


            //Get location curve of beam
            LocationCurve lc   = myBeam.Location as LocationCurve;
            Line          line = lc.Curve as Line;

            //Get vector of location cuver beam
            XYZ p = line.GetEndPoint(0);
            XYZ q = line.GetEndPoint(1);
            XYZ v = q - p; // Vector equation of line

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

            //Set current Beam be Joined

            //setBeJoined(myBeam);

            while (true)
            {
                #region Pick faces
                //Pick Face end

                List <Reference> myListRef = uiDoc.Selection.PickObjects(ObjectType.Face) as List <Reference>;

                List <Face> myListFacePicked = new List <Face>();

                foreach (Reference myRef in myListRef)
                {
                    Element E = doc.GetElement(myRef);

                    GeometryObject myGeoObj = E.GetGeometryObjectFromReference(myRef);

                    Face myPickedFace = myGeoObj as Face;

                    myListFacePicked.Add(myPickedFace);
                }
                #endregion


                #region Error picked faces
                if (myListFacePicked.Count != 2 && myListFacePicked.Count != 4)
                {
                    TaskDialog.Show("Error!", "Chua ho tro lua chon: " + myListFacePicked.Count() + " mat, Chon 2 hoac 4 mat");
                    continue;
                }

                #endregion

                else
                {
                    string caseDistributionRebar = "Case 2: 4 Faces";

                    List <double> myListSpace = new List <double>()
                    {
                        pitch_1, pitch_2, pitch_3, pitch_3, pitch_2, pitch_1
                    };
                    List <double> myListSpace_C1 = new List <double>()
                    {
                        pitch_1_C1, pitch_2_C1, pitch_3_C1, pitch_3_C1, pitch_2_C1, pitch_1_C1
                    };
                    if (myListFacePicked.Count == 2)
                    {
                        myListSpace = new List <double>()
                        {
                            pitch_1, pitch_2, pitch_1, pitch_2, pitch_2, pitch_1
                        };
                        myListSpace_C1 = new List <double>()
                        {
                            pitch_1_C1, pitch_2_C1, pitch_1_C1, pitch_2_C1, pitch_2_C1, pitch_1_C1
                        };
                        caseDistributionRebar = "Case 1: 2 Faces";
                    }
                    TaskDialog.Show("Info", caseDistributionRebar);

                    if (isSt1Yes)
                    {
                        #region Rebar stirrup

                        // List of boundaries faces
                        List <double> myListEndPointDis = getAndSortDisOfEndFaces(myListFacePicked, pE);
                        myListEndPointDis.Sort();

                        Dictionary <double, double> myDicDisNumDetail = detailListDistance_Update_MaxSpace(myListEndPointDis,
                                                                                                           factor,
                                                                                                           delta_1, pitch_1,
                                                                                                           pitch_2,
                                                                                                           delta_3, pitch_3, N3);

                        foreach (Rebar myRebar in myListRebar)
                        {
                            List <ElementId> myListRebarCopyId = copyRebarByDistance_Update_MaxSpace(doc, myRebar, myDicDisNumDetail);


                            List <double> myDistances = myDicDisNumDetail.Keys.ToList();
                            myDistances.Sort();

                            List <double> myListNum = new List <double>();

                            foreach (double key in myDistances)
                            {
                                myListNum.Add(myDicDisNumDetail[key]);
                            }


                            // using transcation (edit DB)
                            for (int i = 0; i < myListRebarCopyId.Count(); i++)
                            {
                                using (Transaction myTrans = new Transaction(doc, "CopyElementByCoordinate"))

                                {
                                    myTrans.Start();
                                    ElementId rebarId  = myListRebarCopyId[i];
                                    Rebar     myRebarI = doc.GetElement(rebarId) as Rebar;

                                    if (i == 1 || i == 4)
                                    {
                                        if (myListNum[i] / myListSpace[i] < 1)
                                        {
                                            myRebarI.GetShapeDrivenAccessor().SetLayoutAsSingle();
                                        }

                                        else
                                        {
                                            myRebarI.GetShapeDrivenAccessor().SetLayoutAsMaximumSpacing(myListSpace[i], (myListNum[i]), isOpposite, false, false);
                                        }
                                    }

                                    else
                                    {
                                        if (myListNum[i] / myListSpace[i] < 1)
                                        {
                                            myRebarI.GetShapeDrivenAccessor().SetLayoutAsSingle();
                                        }

                                        else
                                        {
                                            myRebarI.GetShapeDrivenAccessor().SetLayoutAsMaximumSpacing(myListSpace[i], (myListNum[i]), isOpposite, true, true);
                                        }
                                    }

                                    myTrans.Commit();
                                }
                            }
                        }
                        #endregion
                    }


                    if (isYes_C1)
                    {
                        #region Rebar C stirrup

                        // List of boundaries faces
                        List <double> myListEndPointDis_C1 = getAndSortDisOfEndFaces(myListFacePicked, pE);
                        myListEndPointDis_C1.Sort();

                        Dictionary <double, double> myDicDisNumDetail_C1 = detailListDistance_Update_MaxSpace(myListEndPointDis_C1,
                                                                                                              factor_C1,
                                                                                                              delta_1_C1, pitch_1_C1,
                                                                                                              pitch_2_C1,
                                                                                                              delta_3_C1, pitch_3_C1, N3_C1);

                        foreach (Rebar myRebar in myListRebar_C1)
                        {
                            List <ElementId> myListRebarCopyId_C1 = copyRebarByDistance_Update_MaxSpace(doc, myRebar, myDicDisNumDetail_C1);


                            List <double> myDistances_C1 = myDicDisNumDetail_C1.Keys.ToList();
                            myDistances_C1.Sort();

                            List <double> myListNum_C1 = new List <double>();

                            foreach (double key in myDistances_C1)
                            {
                                myListNum_C1.Add(myDicDisNumDetail_C1[key]);
                            }


                            // using transcation (edit DB)
                            for (int i = 0; i < myListRebarCopyId_C1.Count(); i++)
                            {
                                using (Transaction myTrans = new Transaction(doc, "CopyElementByCoordinate"))

                                {
                                    myTrans.Start();
                                    ElementId rebarId  = myListRebarCopyId_C1[i];
                                    Rebar     myRebarI = doc.GetElement(rebarId) as Rebar;

                                    if (i == 1 || i == 4)
                                    {
                                        if (myListNum_C1[i] / myListSpace_C1[i] < 1)
                                        {
                                            myRebarI.GetShapeDrivenAccessor().SetLayoutAsSingle();
                                        }

                                        else
                                        {
                                            myRebarI.GetShapeDrivenAccessor().SetLayoutAsMaximumSpacing(myListSpace_C1[i], (myListNum_C1[i]), isOpposite, false, false);
                                        }
                                    }

                                    else
                                    {
                                        if (myListNum_C1[i] / myListSpace_C1[i] < 1)
                                        {
                                            myRebarI.GetShapeDrivenAccessor().SetLayoutAsSingle();
                                        }

                                        else
                                        {
                                            myRebarI.GetShapeDrivenAccessor().SetLayoutAsMaximumSpacing(myListSpace_C1[i], (myListNum_C1[i]), isOpposite, true, true);
                                        }
                                    }

                                    myTrans.Commit();
                                }
                            }
                        }
                        #endregion
                    }


                    if (isLB1Yes)
                    {
                        testRebar_FromCurve_Bot_Func(doc, myBeam, myListFacePicked, FB1, CB1,
                                                     rebaNameShape_L1, rebaNameType_L1);
                    }
                    if (isLB2Yes)
                    {
                        testRebar_FromCurve_Bot_Func(doc, myBeam, myListFacePicked, FB2, CB2,
                                                     rebaNameShape_L2, rebaNameType_L2);
                    }
                }
            }
        }
예제 #14
0
        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();
            }
        }