Exemplo n.º 1
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();
                    }
                }
            }
        }
Exemplo n.º 2
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());

            //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(doc, 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(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);
                    }
                }
            }
        }
Exemplo n.º 4
0
        public void rebarBeamTop_Form(UIDocument uiDoc)
        {
            Document doc = uiDoc.Document;

            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>();


            // Top 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.RebarShap1Top_Cb.Items.Add(myRebarShape.Name);
                        myInputFormSetting.RebarShap2Top_Cb.Items.Add(myRebarShape.Name);
                    }


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


                    myInputFormSetting.ShowDialog();


                    //Shape
                    rebaNameShape_L1 = myInputFormSetting.RebarShap1Top_Cb.Text;
                    rebaNameShape_L2 = myInputFormSetting.RebarShap2Top_Cb.Text;

                    //type
                    rebaNameType_L1 = myInputFormSetting.RebarType1Top_Cb.Text;
                    rebaNameType_L2 = myInputFormSetting.RebarType2Top_Cb.Text;


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

                    // Layer1

                    FB1 = Convert.ToDouble(myInputFormSetting.FT1_Tb.Text);
                    CB1 = Convert.ToDouble(myInputFormSetting.CT1_Tb.Text) / myConvertFactor;


                    // Bottom Layer
                    // Layer2

                    FB2 = Convert.ToDouble(myInputFormSetting.FT2_Tb.Text);
                    CB2 = Convert.ToDouble(myInputFormSetting.CT2_Tb.Text) / myConvertFactor;


                    if (myInputFormSetting.yes1Top_Chb.Checked == false && myInputFormSetting.yes2Top_Chb.Checked == false)
                    {
                        TaskDialog.Show("Warning!", "Tich vao Yes/No de bo tri it nhat 1 lop");
                    }
                    else
                    {
                        //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("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);



            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...");

            Element 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(doc, 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 != 4)
                {
                    TaskDialog.Show("Error!", "Chua ho tro lua chon: " + myListFacePicked.Count() + " mat, Chon 4 mat");
                    continue;
                }

                #endregion

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

                    if (myListFacePicked.Count == 2)
                    {
                        caseDistributionRebar = "Case 1: 2 Faces";
                    }
                    TaskDialog.Show("Info", caseDistributionRebar);



                    if (isLB1Yes)
                    {
                        Rebar_FromCurve_Top_Func(doc, myBeam, myListFacePicked, FB1, CB1,
                                                 rebaNameShape_L1, rebaNameType_L1);
                    }
                    if (isLB2Yes)
                    {
                        Rebar_FromCurve_Top_Func(doc, myBeam, myListFacePicked, FB2, CB2,
                                                 rebaNameShape_L2, rebaNameType_L2);
                    }
                }
            }
        }