Exemplo n.º 1
0
        public static List <ResultsR> GetResults()
        {
            List <ResultsR>      Results      = new List <ResultsR>();
            IRobotCollection     Bars         = robotApp.Project.Structure.Bars.GetAll();
            IRobotCaseCollection LoadingCases = robotApp.Project.Structure.Cases.GetAll();

            for (int i = 1; i <= Bars.Count; i++)
            {
                IRobotBar Element = Bars.Get(i);
                for (int j = 1; j <= LoadingCases.Count; j++)
                {
                    IRobotCase         Case      = LoadingCases.Get(j);
                    int                caseNum   = Case.Number;
                    IRobotBarForceData Force     = barForceServer.Value(i, caseNum, 0.5);
                    double             FX        = Force.FX;
                    double             FY        = Force.FY;
                    double             FZ        = Force.FZ;
                    double             MX        = Force.MX;
                    double             MY        = Force.MY;
                    double             MZ        = Force.MZ;
                    double             KY        = Force.KY;
                    double             KZ        = Force.KZ;
                    ResultsR           barResult = new ResultsR(FX, FY, FZ, MX, MY, MZ, KY, KZ);
                    Results.Add(barResult);
                }
            }
            return(Results);
        }
Exemplo n.º 2
0
        public static void GetResults()
        {
            IRobotCollection     Bars         = robotApp.Project.Structure.Bars.GetAll();
            IRobotCaseCollection LoadingCases = robotApp.Project.Structure.Cases.GetAll();

            for (int i = 1; i <= Bars.Count; i++)
            {
                IRobotBar Element = Bars.Get(i);
                for (int j = 1; j <= LoadingCases.Count; j++)
                {
                    IRobotCase         Case    = LoadingCases.Get(j);
                    int                caseNum = Case.Number;
                    IRobotBarForceData Force   = barForceServer.Value(i, caseNum, 0.5);
                    double             FX      = Force.FX;
                    double             FY      = Force.FY;
                    double             FZ      = Force.FZ;
                    double             MX      = Force.MX;
                    double             MY      = Force.MY;
                    double             MZ      = Force.MZ;
                }
            }
        }
Exemplo n.º 3
0
        public void CopyData()
        {
            button1.Text = "Loading...";
            //this.WindowState = FormWindowState.Minimized;
            RobotApplication robapp = new RobotApplication();

            //-------------------------------------
            //Load Cases
            IRobotCaseCollection robotCaseCollection = robapp.Project.Structure.Cases.GetAll();
            int loadCase = 0;

            int FindCase(string casename)
            {
                int        number    = 1;
                IRobotCase robotCase = robapp.Project.Structure.Cases.Get(1);

                for (int i = 0; i < robotCaseCollection.Count; i++)
                {
                    robotCase = robapp.Project.Structure.Cases.Get(i);
                    if (robotCase != null)
                    {
                        if (robotCase.Name == casename)
                        {
                            number = i;
                            break;
                        }
                    }
                }
                loadCase = number;
                return(number);
            }

            //-------------------------------------
            //Get Number of Bars Selected
            RobotSelection barSel = robapp.Project.Structure.Selections.Get(IRobotObjectType.I_OT_BAR);
            //Get All Load Cases
            RobotSelection casSel = robapp.Project.Structure.Selections.Get(IRobotObjectType.I_OT_CASE);

            //Get Bar and Node Data
            IRobotBarServer  robotBarServer = robapp.Project.Structure.Bars;
            IRobotNodeServer inds           = robapp.Project.Structure.Nodes;

            //Get a List of the bars and Setup bar information Struct
            int[]            barSelArray = new int[barSel.Count];
            BeamDataStruct[] beamData    = new BeamDataStruct[barSelArray.Length];
            for (int i = 1; i < barSel.Count + 1; i++)
            {
                //Setup bar no. array
                barSelArray[i - 1] = barSel.Get(i);

                //Get node information from bar data
                IRobotBar  bar         = (IRobotBar)robotBarServer.Get(barSelArray[i - 1]);
                int        startNodeNo = bar.StartNode;
                int        endNodeNo   = bar.EndNode;
                IRobotNode startNode   = (IRobotNode)inds.Get(startNodeNo);
                IRobotNode endNode     = (IRobotNode)inds.Get(endNodeNo);

                //If a Beam, Skip
                if (startNode.Z == endNode.Z)
                {
                    continue;
                }

                //Which is highest node
                IRobotNode node = (startNode.Z > endNode.Z) ? startNode : endNode;

                //Populate beam data from node and bar data.
                beamData[i - 1].barNo            = barSelArray[i - 1];
                beamData[i - 1].section          = bar.GetLabel(IRobotLabelType.I_LT_BAR_SECTION).Name.ToString();
                beamData[i - 1].x                = node.X;
                beamData[i - 1].y                = node.Y;
                beamData[i - 1].z                = node.Z;
                beamData[i - 1].height           = bar.Length;
                beamData[i - 1].concreteStrength = bar.GetLabel(IRobotLabelType.I_LT_MATERIAL).Name.ToString();

                //textBox2.AppendText(beamData[i - 1].barNo.ToString() + "\t : " + beamData[i - 1].section.ToString() + "\t : " +
                //    beamData[i - 1].x.ToString("F3") + "\t : " + beamData[i - 1].y.ToString("F3") + "\t : " + beamData[i - 1].z.ToString("F3") + "\r\n");
            }

            textBox2.AppendText("\r\nSorting\r\n");
            beamData = beamData.OrderBy(x => x.z).ToArray();
            beamData = beamData.OrderBy(x => x.y).ToArray();
            beamData = beamData.OrderBy(x => x.x).ToArray();

            int group      = 1;
            int posInGroup = 0;

            for (int i = 0; i < beamData.Length; i++)
            {
                posInGroup = 0;


                for (int j = 0; j < beamData.Length; j++)
                {
                    if (beamData[i].x - beamData[j].x < 0.0001 && beamData[i].y - beamData[j].y < 0.0001 && beamData[i].barNo != beamData[j].barNo)
                    {
                        if (beamData[j].group != 0)
                        {
                            beamData[i].group = beamData[j].group;
                            for (int k = 0; k < beamData.Length; k++)
                            {
                                if (beamData[i].group == beamData[k].group && beamData[i].barNo != beamData[k].barNo)
                                {
                                    posInGroup++;
                                }
                            }
                            beamData[i].posInGroup = posInGroup;
                        }
                        else
                        {
                            beamData[i].group = group;
                            group++;
                        }
                        break;
                    }
                }
            }

            //Estimate Calculation time



            void QueryResults()
            {
                //RobotExtremeParams robotExtremeParams = robapp.CmpntFactory.Create(IRobotComponentType.I_CT_EXTREME_PARAMS);
                robapp.Project.Structure.Selections.Get(IRobotObjectType.I_OT_CASE).FromText(FindCase(listBox1.SelectedItem.ToString()).ToString());
                //robotExtremeParams.Selection.Set(IRobotObjectType.I_OT_CASE, casSel);
                //IRobotBarForceServer robotBarResultServer = robapp.Project.Structure.Results.Bars.Forces;

                for (int i = 0; i < beamData.Length; i++)
                {
                    robapp.Project.Structure.Selections.Get(IRobotObjectType.I_OT_BAR).FromText(beamData[i].barNo.ToString());
                    //robotExtremeParams.Selection.Set(IRobotObjectType.I_OT_BAR, barSel);

                    IRobotResultQueryReturnType res          = new IRobotResultQueryReturnType();
                    RobotResultQueryParams      queryParams  = new RobotResultQueryParams();
                    RobotResultRowSet           resultRowSet = new RobotResultRowSet();

                    queryParams = robapp.CmpntFactory.Create(IRobotComponentType.I_CT_RESULT_QUERY_PARAMS);
                    queryParams.Selection.Set(IRobotObjectType.I_OT_BAR, barSel);
                    queryParams.Selection.Set(IRobotObjectType.I_OT_CASE, casSel);

                    //queryParams.SetParam(IRobotResultParamType.I_RPT_BAR, );

                    queryParams.ResultIds.SetSize(3);
                    queryParams.ResultIds.Set(1, 167);
                    queryParams.ResultIds.Set(2, 168);
                    queryParams.ResultIds.Set(3, 169);

                    res = robapp.Project.Structure.Results.Query(queryParams, resultRowSet);

                    textBox2.AppendText(resultRowSet.CurrentRow.GetValue(resultRowSet.ResultIds.Get(2)).ToString());
                }
            }

            void CalculateResults()
            {
                textBox2.AppendText($"\r\nStarting calculation: {DateTime.Now.ToString("h:mm:ss tt")}");
                RobotExtremeParams robotExtremeParams = robapp.CmpntFactory.Create(IRobotComponentType.I_CT_EXTREME_PARAMS);

                robapp.Project.Structure.Selections.Get(IRobotObjectType.I_OT_CASE).FromText(FindCase(listBox1.SelectedItem.ToString()).ToString());
                robotExtremeParams.Selection.Set(IRobotObjectType.I_OT_CASE, casSel);
                IRobotBarForceServer robotBarResultServer = robapp.Project.Structure.Results.Bars.Forces;
                int  total     = beamData.Length;
                bool firstLoop = true;

                for (int i = 0; i < beamData.Length; i++)
                {
                    DateTime startTime = DateTime.Now;
                    textBox2.AppendText($"\r\nStart Calculation {i + 1} / {total} before bar selection: {DateTime.Now.ToString("h:mm:ss tt")}");
                    robapp.Project.Structure.Selections.Get(IRobotObjectType.I_OT_BAR).FromText(beamData[i].barNo.ToString());
                    robotExtremeParams.Selection.Set(IRobotObjectType.I_OT_BAR, barSel);


                    //MZ
                    robotExtremeParams.ValueType = IRobotExtremeValueType.I_EVT_FORCE_BAR_MZ;

                    if (Math.Abs(robapp.Project.Structure.Results.Extremes.MaxValue(robotExtremeParams).Value) > Math.Abs(robapp.Project.Structure.Results.Extremes.MinValue(robotExtremeParams).Value))
                    {
                        beamData[i].mZForceServer    = robotBarResultServer.ValueEx(beamData[i].barNo, loadCase, robapp.Project.Structure.Results.Extremes.MaxValue(robotExtremeParams).CaseCmpnt, 1);
                        beamData[i].mZForceServerbtm = robotBarResultServer.ValueEx(beamData[i].barNo, loadCase, robapp.Project.Structure.Results.Extremes.MaxValue(robotExtremeParams).CaseCmpnt, 0);
                    }
                    else
                    {
                        beamData[i].mZForceServer    = robotBarResultServer.ValueEx(beamData[i].barNo, loadCase, robapp.Project.Structure.Results.Extremes.MinValue(robotExtremeParams).CaseCmpnt, 1);
                        beamData[i].mZForceServerbtm = robotBarResultServer.ValueEx(beamData[i].barNo, loadCase, robapp.Project.Structure.Results.Extremes.MinValue(robotExtremeParams).CaseCmpnt, 0);
                    }

                    if (Math.Abs(beamData[i].mZForceServer.MZ) > Math.Abs(beamData[i].mZForceServerbtm.MZ))
                    {
                        //do nothing
                    }
                    else
                    {
                        IRobotBarForceData holder = beamData[i].mZForceServer;
                        beamData[i].mZForceServer    = beamData[i].mZForceServerbtm;
                        beamData[i].mZForceServerbtm = holder;
                    }



                    //MY
                    robotExtremeParams.ValueType = IRobotExtremeValueType.I_EVT_FORCE_BAR_MY;

                    if (Math.Abs(robapp.Project.Structure.Results.Extremes.MaxValue(robotExtremeParams).Value) > Math.Abs(robapp.Project.Structure.Results.Extremes.MinValue(robotExtremeParams).Value))
                    {
                        beamData[i].mYForceServer    = robotBarResultServer.ValueEx(beamData[i].barNo, loadCase, robapp.Project.Structure.Results.Extremes.MaxValue(robotExtremeParams).CaseCmpnt, 1);
                        beamData[i].mYForceServerbtm = robotBarResultServer.ValueEx(beamData[i].barNo, loadCase, robapp.Project.Structure.Results.Extremes.MaxValue(robotExtremeParams).CaseCmpnt, 0);
                    }
                    else
                    {
                        beamData[i].mYForceServer    = robotBarResultServer.ValueEx(beamData[i].barNo, loadCase, robapp.Project.Structure.Results.Extremes.MinValue(robotExtremeParams).CaseCmpnt, 1);
                        beamData[i].mYForceServerbtm = robotBarResultServer.ValueEx(beamData[i].barNo, loadCase, robapp.Project.Structure.Results.Extremes.MinValue(robotExtremeParams).CaseCmpnt, 0);
                    }

                    if (Math.Abs(beamData[i].mYForceServer.MY) > Math.Abs(beamData[i].mYForceServerbtm.MY))
                    {
                        //do nothing
                    }
                    else
                    {
                        IRobotBarForceData holder = beamData[i].mYForceServer;
                        beamData[i].mYForceServer    = beamData[i].mYForceServerbtm;
                        beamData[i].mYForceServerbtm = holder;
                    }



                    //FX
                    robotExtremeParams.ValueType = IRobotExtremeValueType.I_EVT_FORCE_BAR_FX;

                    if (Math.Abs(robapp.Project.Structure.Results.Extremes.MaxValue(robotExtremeParams).Value) > Math.Abs(robapp.Project.Structure.Results.Extremes.MinValue(robotExtremeParams).Value))
                    {
                        beamData[i].fXForceServer    = robotBarResultServer.ValueEx(beamData[i].barNo, loadCase, robapp.Project.Structure.Results.Extremes.MaxValue(robotExtremeParams).CaseCmpnt, 1);
                        beamData[i].fXForceServerbtm = robotBarResultServer.ValueEx(beamData[i].barNo, loadCase, robapp.Project.Structure.Results.Extremes.MaxValue(robotExtremeParams).CaseCmpnt, 0);
                    }
                    else
                    {
                        beamData[i].fXForceServer    = robotBarResultServer.ValueEx(beamData[i].barNo, loadCase, robapp.Project.Structure.Results.Extremes.MinValue(robotExtremeParams).CaseCmpnt, 1);
                        beamData[i].fXForceServerbtm = robotBarResultServer.ValueEx(beamData[i].barNo, loadCase, robapp.Project.Structure.Results.Extremes.MinValue(robotExtremeParams).CaseCmpnt, 0);
                    }
                    double totalTime = (DateTime.Now - startTime).TotalSeconds;
                    textBox2.AppendText($"\r\nEnd Calculation {i + 1} / {total} {DateTime.Now.ToString("h:mm:ss tt")} \r\nTime taken: {totalTime}");

                    if (Math.Abs(beamData[i].fXForceServer.FX) > Math.Abs(beamData[i].fXForceServerbtm.FX))
                    {
                        //do nothing
                    }
                    else
                    {
                        IRobotBarForceData holder = beamData[i].fXForceServer;
                        beamData[i].fXForceServer    = beamData[i].fXForceServerbtm;
                        beamData[i].fXForceServerbtm = holder;
                    }



                    if (firstLoop)
                    {
                        textBox2.AppendText($"\r\nEstimated finish time: {DateTime.Now.AddSeconds(total * totalTime).ToString("h:mm:ss tt")}");
                        firstLoop = false;
                    }
                }
            }

            int maxCol = 1;

            void WriteResults()
            {
                int column       = 1;
                int currentGroup = 0;

                for (int i = 0; i < beamData.Length; i++)
                {
                    if (beamData[i].group == currentGroup)
                    {
                        column = beamData[i].posInGroup;
                        if (column >= maxCol)
                        {
                            maxCol = column;
                        }
                    }
                    else
                    {
                        currentGroup++;
                        column = 0;
                    }

                    int row       = currentGroup + 2;
                    int columnPos = beamData[i].posInGroup + 1;
                    WriteCell(row, 0, columnPos.ToString());

                    WriteCell(row, 1 + 22 * column, beamData[i].section.ToString());
                    WriteCell(row, 2 + 22 * column, beamData[i].barNo.ToString());
                    WriteCell(row, 3 + 22 * column, beamData[i].concreteStrength.ToString());
                    WriteCell(row, 4 + 22 * column, beamData[i].group.ToString());
                    WriteCell(row, 5 + 22 * column, beamData[i].posInGroup.ToString());
                    WriteCell(row, 6 + 22 * column, beamData[i].height.ToString());

                    WriteCell(row, 7 + 22 * column, (beamData[i].fXForceServer.FX / 1000).ToString());
                    WriteCell(row, 8 + 22 * column, (beamData[i].fXForceServer.MY / 1000).ToString());
                    WriteCell(row, 9 + 22 * column, (beamData[i].fXForceServer.MZ / 1000).ToString());
                    WriteCell(row, 10 + 22 * column, (beamData[i].fXForceServerbtm.MY / 1000).ToString());
                    WriteCell(row, 11 + 22 * column, (beamData[i].fXForceServerbtm.MZ / 1000).ToString());


                    WriteCell(row, 12 + 22 * column, (beamData[i].mZForceServer.FX / 1000).ToString());
                    WriteCell(row, 13 + 22 * column, (beamData[i].mZForceServer.MY / 1000).ToString());
                    WriteCell(row, 14 + 22 * column, (beamData[i].mZForceServer.MZ / 1000).ToString());
                    WriteCell(row, 15 + 22 * column, (beamData[i].mZForceServerbtm.MY / 1000).ToString());
                    WriteCell(row, 16 + 22 * column, (beamData[i].mZForceServerbtm.MZ / 1000).ToString());


                    WriteCell(row, 17 + 22 * column, (beamData[i].mYForceServer.FX / 1000).ToString());
                    WriteCell(row, 18 + 22 * column, (beamData[i].mYForceServer.MY / 1000).ToString());
                    WriteCell(row, 19 + 22 * column, (beamData[i].mYForceServer.MZ / 1000).ToString());
                    WriteCell(row, 20 + 22 * column, (beamData[i].mYForceServerbtm.MY / 1000).ToString());
                    WriteCell(row, 21 + 22 * column, (beamData[i].mYForceServerbtm.MZ / 1000).ToString());
                }

                WriteCell(0, 0, currentGroup.ToString());
            }

            void PopulateHeaders()
            {
                for (int i = 0; i <= maxCol; i++)
                {
                    //Headers
                    WriteCell(1, 1 + 22 * i, "Cross Section");
                    WriteCell(1, 2 + 22 * i, "Bar No.");
                    WriteCell(1, 3 + 22 * i, "Concrete Strength");
                    WriteCell(1, 4 + 22 * i, "Group");
                    WriteCell(1, 5 + 22 * i, "Pos In Group");
                    WriteCell(1, 6 + 22 * i, "Length");

                    //FZ Max
                    WriteCell(1, 7 + 22 * i, "Fx (Max) [kN]");
                    WriteCell(1, 8 + 22 * i, "My (Top) [kNm]");
                    WriteCell(1, 9 + 22 * i, "Mz (Top) [kNm]");
                    WriteCell(1, 10 + 22 * i, "My (Btm) [kNm]");
                    WriteCell(1, 11 + 22 * i, "Mz (Btm) [kNm]");

                    //MX Max
                    WriteCell(1, 12 + 22 * i, "Fx (Max) [kN]");
                    WriteCell(1, 13 + 22 * i, "My (Top) [kNm]");
                    WriteCell(1, 14 + 22 * i, "Mz (Top) [kNm]");
                    WriteCell(1, 15 + 22 * i, "My (Btm) [kNm]");
                    WriteCell(1, 16 + 22 * i, "Mz (Btm) [kNm]");

                    //MY Max
                    WriteCell(1, 17 + 22 * i, "Fx (Max) [kN])");
                    WriteCell(1, 18 + 22 * i, "My (Top) [kNm]");
                    WriteCell(1, 19 + 22 * i, "Mz (Top) [kNm]");
                    WriteCell(1, 20 + 22 * i, "My (Btm) [kNm]");
                    WriteCell(1, 21 + 22 * i, "Mz (Btm) [kNm]");

                    //Headers
                    WriteCell(0, 9 + 22 * i, "Fx (Max)");
                    WriteCell(0, 14 + 22 * i, "Mz (Max)");
                    WriteCell(0, 19 + 22 * i, "My (Max)");
                }
            }

            WriteData();
            CalculateResults();
            WriteResults();
            PopulateHeaders();
            SaveExcel();
            CloseExcel();
            button1.Text = "Start";
            textBox2.AppendText("\r\nDone, view your documents for the file named 'Results for bars ~date~', you may close this window or select more columns and press 'Start'.");
            robapp           = null;
            this.WindowState = FormWindowState.Normal;
        }