Exemple #1
0
        private double getDelta_0(Document doc, Rebar myRebar)
        {
            //UIDocument uiDoc = this.ActiveUIDocument;
            //Document doc = uiDoc.Document;

            //Get diameter of rebar

            RebarBarType myRbType        = doc.GetElement(myRebar.GetTypeId()) as RebarBarType;
            double       myRebarDiameter = myRbType.BarDiameter;

            // Get host of rebar

            ElementId myBeamId = myRebar.GetHostId();

            Element myBeam = doc.GetElement(myBeamId);

            if (myBeam.Category.Name != "Structural Framing")
            {
                TaskDialog.Show("Loi!", "Hay chon 1 rebar co host la 1 Structural Framing");
                return(10000000);
            }

            else
            {
                //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 middlePoint = myRebar.get_BoundingBox(null).Max.Add(myRebar.get_BoundingBox(null).Min) / 2;

                // NOTE LAM TRON SO
                //			    middlePoint = new XYZ(middlePoint.X,middlePoint.Y),
                //			                          Math.Round(middlePoint.Z,1));
                double delta_0 = Math.Sqrt(Math.Pow(middlePoint.X - p.X, 2) + Math.Pow(middlePoint.Y - p.Y, 2)) - myRebarDiameter / 2;

                return(delta_0);
            }
        }
Exemple #2
0
        public static Dictionary <string, object> getHostElement(List <Revit.Elements.Element> elements)
        {
            Document doc = DocumentManager.Instance.CurrentDBDocument;
            List <Revit.Elements.Element> elIdList = new List <Revit.Elements.Element>();

            //UIApplication uiapp = DocumentManager.Instance.CurrentUIApplication;
            //Autodesk.Revit.ApplicationServices.Application app = uiapp.Application;
            //UIDocument uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument;

            foreach (Revit.Elements.Element e in elements)
            {
                Autodesk.Revit.DB.Element el = doc.GetElement(e.UniqueId.ToString());
                Rebar     r    = el as Rebar;
                ElementId elId = r.GetHostId();
                elIdList.Add(doc.GetElement(elId).ToDSType(true));
            }

            return(new Dictionary <string, object>
            {
                { "hostElements", elIdList },
            });
        }
        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);
        }
Exemple #4
0
        protected override void PopulateDbRow(Element element, DataRow row)
        {
            Rebar rebar = element as Rebar;

            base.SetDbRowIDAndHostId(rebar, rebar.Document.GetElement(rebar.GetHostId()), row);
        }
        private void Stream( ArrayList data, Rebar rebar )
        {
            data.Add( new Snoop.Data.ClassSeparator( typeof( Rebar ) ) );

              data.Add( new Snoop.Data.ElementId( "Bar type", rebar.GetTypeId(), rebar.Document ) );
              data.Add( new Snoop.Data.ElementId( "Rebar shape", rebar.RebarShapeId, rebar.Document ) );
              data.Add( new Snoop.Data.ElementId( "Host", rebar.GetHostId(), rebar.Document ) );
              data.Add( new Snoop.Data.Object( "Distribution path", rebar.GetDistributionPath() ) );
              data.Add( new Snoop.Data.Enumerable( "GetCenterlineCurves(false, false, false)", rebar.GetCenterlineCurves( false, false, false ) ) );
              data.Add( new Snoop.Data.String( "LayoutRule", rebar.LayoutRule.ToString() ) );
              if( rebar.LayoutRule != RebarLayoutRule.Single )
              {
            data.Add( new Snoop.Data.Double( "Distribution path length", rebar.ArrayLength ) );
            data.Add( new Snoop.Data.Int( "Quantity", rebar.Quantity ) );
            data.Add( new Snoop.Data.Int( "NumberOfBarPositions", rebar.NumberOfBarPositions ) );
            data.Add( new Snoop.Data.Double( "MaxSpacing", rebar.MaxSpacing ) );
              }

              //TF
              data.Add( new Snoop.Data.Object( "ConstraintsManager", rebar.GetRebarConstraintsManager() ) );
              //TFEND
        }
Exemple #6
0
        private List <ElementId> copyRebarByDistance(Document doc, Rebar myRebar, List <double> myDistances)
        {
            //UIDocument uiDoc = this.ActiveUIDocument;
            //Document doc = uiDoc.Document;

            //Get Id rebar
            ElementId myIdRebar = myRebar.Id;


            //Get Id Beam
            ElementId myIdBeam = myRebar.GetHostId();

            Element myBeam = doc.GetElement(myIdBeam);


            if (myBeam.Category.Name != "Structural Framing")
            {
                TaskDialog.Show("Loi!", "Hay chon 1 rebar co host la 1 Structural Framing");
                return(null);
            }

            else
            {
                LocationCurve cur     = myBeam.Location as LocationCurve;
                Line          lineCur = cur.Curve as Line;

                XYZ    q           = lineCur.GetEndPoint(0);
                XYZ    p           = lineCur.GetEndPoint(1);
                XYZ    v           = p - q;
                double lengCurLine = v.GetLength();


                List <XYZ> myCoors = new List <XYZ>();


                double delta0 = getDelta_0(doc, myRebar);

                if (delta0 == 10000000)
                {
                    return(null);
                }

                foreach (double distance in myDistances)
                {
                    XYZ myPointPlace = ((distance - delta0) / lengCurLine) * v;
                    myCoors.Add(myPointPlace);
                }

                if (myCoors.Count < 1)
                {
                    TaskDialog.Show("Loi!", "Khong the copy...");
                    return(null);
                }

                ICollection <ElementId> myRebarIdCol;
                List <ElementId>        myListIdRebar = new List <ElementId>();

                // using transcation (edit DB)
                using (Transaction myTrans = new Transaction(doc, "CopyElementByCoordinate"))

                {
                    myTrans.Start();
                    foreach (XYZ myXYZ in myCoors)
                    {
                        myRebarIdCol = ElementTransformUtils.CopyElement(doc, myIdRebar, myXYZ);
                        foreach (ElementId elemRebarId in myRebarIdCol)
                        {
                            myListIdRebar.Add(elemRebarId);
                        }
                    }
                    myTrans.Commit();
                }
                return(myListIdRebar);
            }
        }
Exemple #7
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();
                    }
                }
            }
        }
Exemple #8
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();
            }
        }
Exemple #9
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();
                    }
                }
            }
        }
        private void Stream( ArrayList data, Rebar rebar )
        {
            data.Add( new Snoop.Data.ClassSeparator( typeof( Rebar ) ) );

              data.Add( new Snoop.Data.ElementId( "Bar type", rebar.GetTypeId(), rebar.Document ) );
              data.Add( new Snoop.Data.ElementId( "Rebar shape", rebar.RebarShapeId, rebar.Document ) );
              data.Add( new Snoop.Data.ElementId( "Host", rebar.GetHostId(), rebar.Document ) );
              data.Add( new Snoop.Data.Object( "Distribution path", rebar.GetDistributionPath() ) );
              data.Add( new Snoop.Data.Enumerable( "GetCenterlineCurves(false, false, false)", rebar.GetCenterlineCurves( false, false, false, MultiplanarOption.IncludeOnlyPlanarCurves, 0 ) ) );
              data.Add( new Snoop.Data.String( "LayoutRule", rebar.LayoutRule.ToString() ) );
              if( rebar.LayoutRule != RebarLayoutRule.Single )
              {
            data.Add( new Snoop.Data.Double( "Distribution path length", rebar.ArrayLength ) );
            data.Add( new Snoop.Data.Int( "Quantity", rebar.Quantity ) );
            data.Add( new Snoop.Data.Int( "NumberOfBarPositions", rebar.NumberOfBarPositions ) );
            data.Add( new Snoop.Data.Double( "MaxSpacing", rebar.MaxSpacing ) );
            data.Add( new Snoop.Data.Bool( "BarsOnNormalSide", rebar.BarsOnNormalSide ) );
              }

              data.Add( new Snoop.Data.String( "ScheduleMark", rebar.ScheduleMark ) );
              data.Add( new Snoop.Data.Double( "Volume", rebar.Volume ) );
              data.Add( new Snoop.Data.Double( "TotalLength", rebar.TotalLength ) );
              data.Add( new Snoop.Data.Object( "Normal", rebar.Normal ) );

              //TF
              data.Add( new Snoop.Data.Object( "ConstraintsManager", rebar.GetRebarConstraintsManager() ) );
              //TFEND

              // Bending data
              data.Add( new Snoop.Data.Object( "Bending Data", rebar.GetBendData() ) );

              // Hook information
              addHookInformation2Rebar( data, rebar, 0 );
              addHookInformation2Rebar( data, rebar, 1 );
        }
        private List <ElementId> copyRebarByDistance_Update_MaxSpace(Document doc, Rebar myRebar, Dictionary <double, double> myDicDisNum)
        {
            List <double> myDistances = myDicDisNum.Keys.ToList();

            myDistances.Sort();

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

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


            //Get Id rebar
            ElementId myIdRebar = myRebar.Id;


            //Get Id Beam
            ElementId myIdBeam = myRebar.GetHostId();

            Element myBeam = doc.GetElement(myIdBeam);


            if (myBeam.Category.Name != "Structural Framing")
            {
                TaskDialog.Show("Loi!", "Hay chon 1 rebar co host la 1 Structural Framing");
                return(null);
            }

            else
            {
                LocationCurve cur     = myBeam.Location as LocationCurve;
                Line          lineCur = cur.Curve as Line;


                XYZ    p1          = lineCur.GetEndPoint(0);
                XYZ    q           = lineCur.GetEndPoint(1);
                XYZ    v           = q - p1;
                double lengCurLine = v.GetLength();

                XYZ p = p1 - 0.1 * v;

                List <XYZ> myCoors = new List <XYZ>();

                // NOTE LAM TRON SO

                //Get diameter of rebar

                XYZ middlePoint = myRebar.get_BoundingBox(null).Max.Add(myRebar.get_BoundingBox(null).Min) / 2;

                List <Curve> centerLines = myRebar.GetCenterlineCurves(false, false, false,
                                                                       MultiplanarOption.IncludeOnlyPlanarCurves, 0)
                                           as List <Curve>;


                foreach (Curve myCurBar in centerLines)
                {
                    middlePoint = myCurBar.GetEndPoint(0);
                    break;
                }

                Plane myReBarPlane = Plane.CreateByNormalAndOrigin(v, middlePoint);


                // Distance from first rebar to
                RebarBarType myRbType        = doc.GetElement(myRebar.GetTypeId()) as RebarBarType;
                double       myRebarDiameter = myRbType.BarDiameter;


                XYZ v1 = p - myReBarPlane.Origin;

                double delta_0 = Math.Abs(myReBarPlane.Normal.DotProduct(v1));

                if (delta_0 == 10000000)
                {
                    return(null);
                }

                foreach (double distance in myDistances)
                {
                    XYZ myPointPlace = ((distance - delta_0) / lengCurLine) * v;
                    myCoors.Add(myPointPlace);
                }

                if (myCoors.Count < 1)
                {
                    TaskDialog.Show("Loi!", "Khong the copy...");
                    return(null);
                }

                ICollection <ElementId> myRebarIdCol;
                List <ElementId>        myListIdRebar = new List <ElementId>();

                // using transcation (edit DB)
                using (Transaction myTrans = new Transaction(doc, "CopyElementByCoordinate"))

                {
                    myTrans.Start();
                    foreach (XYZ myXYZ in myCoors)
                    {
                        myRebarIdCol = ElementTransformUtils.CopyElement(doc, myIdRebar, myXYZ);
                        foreach (ElementId elemRebarId in myRebarIdCol)
                        {
                            myListIdRebar.Add(elemRebarId);
                        }
                    }
                    myTrans.Commit();
                }
                return(myListIdRebar);
            }
        }
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            Debug.Listeners.Clear();
            Debug.Listeners.Add(new RbsLogger.Logger("SelectHost"));

            UIDocument       uiDoc  = commandData.Application.ActiveUIDocument;
            Document         doc    = uiDoc.Document;
            Selection        sel    = uiDoc.Selection;
            List <ElementId> selIds = sel.GetElementIds().ToList();

            if (selIds.Count != 1)
            {
                message = "Выберите элемент, для которого нужно найти основу.";
                return(Result.Failed);
            }
            Element selElem = doc.GetElement(selIds.First());

            Debug.WriteLine("Selected elem id: " + selElem.Id.IntegerValue.ToString());
            ElementId hostId = null;


            if (selElem is AreaReinforcement)
            {
                AreaReinforcement el = selElem as AreaReinforcement;
                hostId = el.GetHostId();
                Debug.WriteLine("It is area reinforcement");
            }
            if (selElem is PathReinforcement)
            {
                PathReinforcement el = selElem as PathReinforcement;
                hostId = el.GetHostId();
                Debug.WriteLine("It is path reinforcement");
            }
            if (selElem is Rebar)
            {
                Rebar el = selElem as Rebar;
                hostId = el.GetHostId();
                Debug.WriteLine("It is rebar");
            }
            if (selElem is RebarInSystem)
            {
                RebarInSystem el = selElem as RebarInSystem;
                hostId = el.SystemId;
                Debug.WriteLine("It is rebar in system");
            }

            if (selElem is FamilyInstance)
            {
                FamilyInstance el   = selElem as FamilyInstance;
                Element        host = el.Host;
                if (host != null)
                {
                    hostId = host.Id;
                    Debug.WriteLine("It is family instance with host");
                }
                else
                {
                    Element parentFamily = el.SuperComponent;
                    if (parentFamily != null)
                    {
                        Debug.WriteLine("It is family instance with parent family");
                        hostId = parentFamily.Id;
                    }
                }
            }


            if (hostId == null)
            {
                message = "Не удалось получить родительский элемент.";
                Debug.WriteLine("Host not found");
                return(Result.Failed);
            }
            else
            {
                sel.SetElementIds(new List <ElementId> {
                    hostId
                });
                Debug.WriteLine("Host id: " + hostId.IntegerValue.ToString());
                return(Result.Succeeded);
            }
        }
Exemple #13
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;
        }
Exemple #14
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            //Pegar uidoc e doc
            UIDocument uidoc = commandData.Application.ActiveUIDocument;
            Document   doc   = uidoc.Document;

            try
            {
                //Filtro para pegar apenas vergalhões
                ISelectionFilter selectionFilter = new vergalhaoSelectionFilter();

                //Pegar elemento
                Reference pickedObj = uidoc.Selection.PickObject(ObjectType.Element, selectionFilter, "Selecione uma vergalhão");
                ElementId eleId     = pickedObj.ElementId;
                Element   ele       = doc.GetElement(eleId);
                Rebar     rebar     = ele as Rebar; //Pega o elemento selecionado como um vergalhão

                //Pegar o o ospedeiro do elemento
                ElementId hostId  = rebar.GetHostId();
                Element   hostEle = doc.GetElement(hostId);

                //Pegar a vista ativa e criar um plano com base em sua origem e direção
                View     view     = doc.ActiveView;
                ViewType viewType = view.ViewType;
                XYZ      origem   = view.Origin;
                XYZ      direcao  = view.ViewDirection;
                Plane    plano    = Plane.CreateByNormalAndOrigin(direcao, origem);

                //Forma do vergalhão
                ElementId   shapeId = rebar.GetShapeId();
                ElementType shape   = doc.GetElement(shapeId) as ElementType;

                //Cria o nome da família do item de detalhe, "Detalhe vergalhão 01", "Detalhe vergalhão 22", etc
                String shapeName = "Detalhe vergalhão " + shape.Name;

                //Dimensões do vergalhão, adicionar outras conforme for evoluindo, servirão para alterar a família de item de detalhe
                Double dA = ele.LookupParameter("A").AsDouble();
                Double dB = ele.LookupParameter("B").AsDouble();

                using (Transaction trans = new Transaction(doc, "Criar elemento"))
                {
                    trans.Start();

                    //Variável para guardar o sketchplane
                    SketchPlane sketchPlane;

                    //Pegar o SketchPlane de acordo com o tipo de vista, se for elevação ou corte o SketchPlane será a partir do plano criado anteriormente
                    if (viewType == ViewType.Elevation || viewType == ViewType.Section)
                    {
                        sketchPlane = SketchPlane.Create(doc, plano);
                    }
                    else
                    {
                        sketchPlane = view.SketchPlane;
                    }

                    //Define o SketchPlane da vista
                    view.SketchPlane = sketchPlane;

                    //Procura a família de item de detalhe com base no nome e ativa o mesmo
                    FilteredElementCollector collector = new FilteredElementCollector(doc);
                    IList <Element>          symbols   = collector.OfClass(typeof(FamilySymbol)).WhereElementIsElementType().ToElements();

                    FamilySymbol symbol = null;
                    foreach (Element elem in symbols)
                    {
                        if (elem.Name == shapeName)
                        {
                            symbol = elem as FamilySymbol;
                            break;
                        }
                    }

                    if (!symbol.IsActive)
                    {
                        symbol.Activate();
                    }

                    //Pega o ponto selecionado
                    XYZ pickedPoint = uidoc.Selection.PickPoint();

                    //Cria o item de detalhe no ponto e define seus parâmetros
                    FamilyInstance familyInstance = doc.Create.NewFamilyInstance(pickedPoint, symbol, view);
                    familyInstance.LookupParameter("A").Set(dA);
                    familyInstance.LookupParameter("B").Set(dB);

                    trans.Commit();
                }

                return(Result.Succeeded);
            }
            catch (Exception e)
            {
                message = e.Message;
                return(Result.Failed);
            }
        }
Exemple #15
0
        public static System.Collections.Generic.List <string> GenerateResourceIdsForTableName(Element element, BuiltInCategory categoryId)
        {
            System.Collections.Generic.List <string> list = new System.Collections.Generic.List <string>();
            ElementTypeEnum elementTypeEnum = (element is ElementType) ? ElementTypeEnum.SYMBOL : ElementTypeEnum.INSTANCE;

            list.Add(string.Format("TabN_{0}_{1}", categoryId, elementTypeEnum));
            BuiltInCategory builtInCategory = (BuiltInCategory)(-1);
            bool            flag            = false;
            FamilyInstance  familyInstance  = element as FamilyInstance;

            if (familyInstance != null && familyInstance.Host != null)
            {
                builtInCategory = APIObjectList.GetCategoryId(familyInstance.Host);
                flag            = true;
            }
            else
            {
                LoadBase loadBase = element as LoadBase;
                if (loadBase != null && loadBase.HostElement != null)
                {
                    builtInCategory = APIObjectList.GetCategoryId(loadBase.HostElement);
                    flag            = true;
                }
                else
                {
                    Opening opening = element as Opening;
                    if (opening != null && opening.Host != null)
                    {
                        builtInCategory = APIObjectList.GetCategoryId(opening.Host);
                        list.Add(string.Format("TabN_{0}_{1}", "OST_Type_Opening", builtInCategory));
                        list.Add("TabN_Type_" + opening.GetType().FullName.Replace('.', '_'));
                    }
                    else
                    {
                        Rebar rebar = element as Rebar;
                        if (rebar != null && rebar.GetHostId() != ElementId.InvalidElementId)
                        {
                            builtInCategory = APIObjectList.GetCategoryId(rebar.GetHostId(), rebar.Document);
                            flag            = true;
                        }
                    }
                }
            }
            if (flag)
            {
                list.Add(string.Format("TabN_{0}_{1}", categoryId, builtInCategory));
            }
            if (element is RoomTag)
            {
                list.Add("TabN_Type_" + element.GetType().FullName.Replace('.', '_'));
            }
            if (element != null && element.Id.IntegerValue != -1)
            {
                if (element.LevelId != ElementId.InvalidElementId)
                {
                    list.Add("TabN_CST_ElementLevel");
                }
                if (element.CreatedPhaseId != ElementId.InvalidElementId)
                {
                    list.Add("TabN_CST_ElementPhase");
                }
            }
            return(list);
        }