public void CopyData() { button1.Text = "Loading..."; //this.WindowState = FormWindowState.Minimized; //------------------------------------- //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]; IRobotBarSectionData sectData = bar.GetLabel(IRobotLabelType.I_LT_BAR_SECTION).Data; double depth = sectData.GetValue(IRobotBarSectionDataValue.I_BSDV_BF); double breath = sectData.GetValue(IRobotBarSectionDataValue.I_BSDV_D); if (depth < breath) { double holder = breath; breath = depth; depth = holder; } depth = depth * 1000; breath = breath * 1000; beamData[i - 1].section = $"C1 {depth} x {breath}"; beamData[i - 1].x = node.X; beamData[i - 1].y = node.Y; beamData[i - 1].z = node.Z; beamData[i - 1].height = bar.Length; IRobotMaterialData concrete = bar.GetLabel(IRobotLabelType.I_LT_MATERIAL).Data; Double concreteS = concrete.RE / 1000000; beamData[i - 1].concreteStrength = concreteS.ToString(); } 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; } } } 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; string columnsSelected = ""; 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); } beamData[i].mzValue = Math.Abs(beamData[i].mZForceServer.MZ) > Math.Abs(beamData[i].mZForceServerbtm.MZ) ? beamData[i].mZForceServer.FX : beamData[i].mZForceServerbtm.FX; //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); } beamData[i].myValue = Math.Abs(beamData[i].mYForceServer.MY) > Math.Abs(beamData[i].mYForceServerbtm.MY) ? beamData[i].mYForceServer.FX : beamData[i].mYForceServerbtm.FX; //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); } beamData[i].fxValue = Math.Abs(beamData[i].fXForceServer.FX) > Math.Abs(beamData[i].fXForceServerbtm.FX) ? beamData[i].fXForceServer.FX : beamData[i].fXForceServerbtm.FX; 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 (firstLoop) { textBox2.AppendText($"\r\nEstimated finish time: {DateTime.Now.AddSeconds(total * totalTime).ToString("h:mm:ss tt")}"); firstLoop = false; } columnsSelected += $"{beamData[i].barNo.ToString()} "; } textBox2.AppendText($"\r\ncolumns selected {columnsSelected}"); robapp.Project.Structure.Selections.Get(IRobotObjectType.I_OT_BAR).FromText(columnsSelected); } 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].fxValue / 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].mzValue / 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].myValue / 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; }
private void CreateBars(List <int> forDeadLoadsBars) { //create the tube section //type 1 IRobotLabel sec1 = _structure.Labels.Create(IRobotLabelType.I_LT_BAR_SECTION, "CatiaTubeSection_00"); IRobotBarSectionData data1 = sec1.Data as IRobotBarSectionData; data1.Type = IRobotBarSectionType.I_BST_NS_TUBE; data1.ShapeType = IRobotBarSectionShapeType.I_BSST_USER_TUBE; IRobotBarSectionNonstdData nonst_data1 = data1.CreateNonstd(0); //type 2 IRobotLabel sec2 = _structure.Labels.Create(IRobotLabelType.I_LT_BAR_SECTION, "CatiaTubeSection_01"); IRobotBarSectionData data2 = sec2.Data as IRobotBarSectionData; data2.Type = IRobotBarSectionType.I_BST_NS_TUBE; data2.ShapeType = IRobotBarSectionShapeType.I_BSST_USER_TUBE; IRobotBarSectionNonstdData nonst_data2 = data2.CreateNonstd(0); //type 3 IRobotLabel sec3 = _structure.Labels.Create(IRobotLabelType.I_LT_BAR_SECTION, "CatiaTubeSection_02"); IRobotBarSectionData data3 = sec3.Data as IRobotBarSectionData; data3.Type = IRobotBarSectionType.I_BST_NS_TUBE; data3.ShapeType = IRobotBarSectionShapeType.I_BSST_USER_TUBE; IRobotBarSectionNonstdData nonst_data3 = data3.CreateNonstd(0); //create the plate section IRobotLabel sec4 = _structure.Labels.Create(IRobotLabelType.I_LT_BAR_SECTION, "CatiaPlateSection_00"); IRobotBarSectionData data4 = sec4.Data as IRobotBarSectionData; data4.Type = IRobotBarSectionType.I_BST_NS_RECT; data4.ShapeType = IRobotBarSectionShapeType.I_BSST_USER_RECT; IRobotBarSectionNonstdData nonst_data4 = data4.CreateNonstd(0); IRobotLabel sec5 = _structure.Labels.Create(IRobotLabelType.I_LT_BAR_SECTION, "CatiaPlateSection_01"); IRobotBarSectionData data5 = sec5.Data as IRobotBarSectionData; data5.Type = IRobotBarSectionType.I_BST_NS_RECT; data5.ShapeType = IRobotBarSectionShapeType.I_BSST_USER_RECT; IRobotBarSectionNonstdData nonst_data5 = data5.CreateNonstd(0); IRobotLabel sec6 = _structure.Labels.Create(IRobotLabelType.I_LT_BAR_SECTION, "CatiaPlateSection_02"); IRobotBarSectionData data6 = sec6.Data as IRobotBarSectionData; data6.Type = IRobotBarSectionType.I_BST_NS_RECT; data6.ShapeType = IRobotBarSectionShapeType.I_BSST_USER_RECT; IRobotBarSectionNonstdData nonst_data6 = data6.CreateNonstd(0); //create a cable section IRobotLabel sec7 = _structure.Labels.Create(IRobotLabelType.I_LT_BAR_CABLE, "CatiaCable"); IRobotBarCableData data7 = sec7.Data as IRobotBarCableData; data7.SectionAX = Math.PI * (Math.Pow((_sectionInfo[4] / 1000), 2)); //the area formula using the cable radius parameter data7.MaterialName = "STEEL"; if (_barInfo.Count != 0) { // double sectionDiameter = _barInfo[0].Diameter/1000; //the diameter in meters // double sectionthickness = _barInfo[0].SectionThickness/1000; //the thickness in meters //set the values of the tubes nonst_data1.SetValue(IRobotBarSectionNonstdDataValue.I_BSNDV_TUBE_D, _sectionInfo[0] / 1000); //the section diameter nonst_data1.SetValue(IRobotBarSectionNonstdDataValue.I_BSNDV_TUBE_T, _sectionInfo[1] / 1000); //the section thickness data1.CalcNonstdGeometry(); _structure.Labels.Store(sec1); nonst_data2.SetValue(IRobotBarSectionNonstdDataValue.I_BSNDV_TUBE_D, _sectionInfo[2] / 1000); //the section diameter nonst_data2.SetValue(IRobotBarSectionNonstdDataValue.I_BSNDV_TUBE_T, _sectionInfo[3] / 1000); //the section thickness data2.CalcNonstdGeometry(); _structure.Labels.Store(sec2); nonst_data3.SetValue(IRobotBarSectionNonstdDataValue.I_BSNDV_TUBE_D, _sectionInfo[4] / 1000); //the section diameter nonst_data3.SetValue(IRobotBarSectionNonstdDataValue.I_BSNDV_TUBE_T, _sectionInfo[5] / 1000); //the section thickness data3.CalcNonstdGeometry(); _structure.Labels.Store(sec3); //set the values of the plate nonst_data4.SetValue(IRobotBarSectionNonstdDataValue.I_BSNDV_RECT_H, _sectionInfo[6] / 1000); nonst_data4.SetValue(IRobotBarSectionNonstdDataValue.I_BSNDV_RECT_B, 2 * _sectionInfo[7] / 1000); //generate correct section properties without overlapping thicknesses nonst_data4.SetValue(IRobotBarSectionNonstdDataValue.I_BSNDV_RECT_T, _sectionInfo[7] / 1000); data4.CalcNonstdGeometry(); _structure.Labels.Store(sec4); nonst_data5.SetValue(IRobotBarSectionNonstdDataValue.I_BSNDV_RECT_H, _sectionInfo[8] / 1000); nonst_data5.SetValue(IRobotBarSectionNonstdDataValue.I_BSNDV_RECT_B, 2 * _sectionInfo[9] / 1000); //generate correct section properties without overlapping thicknesses nonst_data5.SetValue(IRobotBarSectionNonstdDataValue.I_BSNDV_RECT_T, _sectionInfo[9] / 1000); data5.CalcNonstdGeometry(); _structure.Labels.Store(sec5); nonst_data6.SetValue(IRobotBarSectionNonstdDataValue.I_BSNDV_RECT_H, _sectionInfo[10] / 1000); nonst_data6.SetValue(IRobotBarSectionNonstdDataValue.I_BSNDV_RECT_B, 2 * _sectionInfo[11] / 1000); //generate correct section properties without overlapping thicknesses nonst_data6.SetValue(IRobotBarSectionNonstdDataValue.I_BSNDV_RECT_T, _sectionInfo[11] / 1000); data6.CalcNonstdGeometry(); _structure.Labels.Store(sec6); //the values of the cable are already set! _structure.Labels.Store(sec7); } int barId = 5000; for (int i = 0; i < _barInfo.Count; i++) { Console.WriteLine("Now creating bar " + barId.ToString() + "..."); var b = (AnalyticalBar)_barInfo[i]; //find the corresponding points in the nodeList to create the bar //int robStart = 0; //int robEnd = 0; //foreach (var n in _nodeInfo) //{ // if (n.catiaID.Equals(b.CatiaStart)) // { // robStart = n.Id; // } // else if (n.catiaID.Equals(b.CatiaEnd)) // { // robEnd = n.robotID; // } // else // { // continue; // } //} //create the bar _bars.Create(barId, b.Start.Id, b.End.Id); //DON'T CREATE A RELEASE - DIFFICULT TO IMPLEMENT // _bars.Get(barId).SetLabel(IRobotLabelType.I_LT_BAR_RELEASE, "CatiaBarRelease"); if (b.SectionType == SectionType.Tube00) { _bars.Get(barId).SetLabel(IRobotLabelType.I_LT_BAR_SECTION, "CatiaTubeSection_00"); } else if (b.SectionType == SectionType.Tube01) { _bars.Get(barId).SetLabel(IRobotLabelType.I_LT_BAR_SECTION, "CatiaTubeSection_01"); } else if (b.SectionType == SectionType.Tube02) { _bars.Get(barId).SetLabel(IRobotLabelType.I_LT_BAR_SECTION, "CatiaTubeSection_02"); } else if (b.SectionType == SectionType.Plate00) { _bars.Get(barId).SetLabel(IRobotLabelType.I_LT_BAR_SECTION, "CatiaPlateSection_00"); } else if (b.SectionType == SectionType.Plate01) { _bars.Get(barId).SetLabel(IRobotLabelType.I_LT_BAR_SECTION, "CatiaPlateSection_01"); } else if (b.SectionType == SectionType.Plate02) { _bars.Get(barId).SetLabel(IRobotLabelType.I_LT_BAR_SECTION, "CatiaPlateSection_02"); } else if (b.SectionType == SectionType.Cable) { _bars.Get(barId).SetLabel(IRobotLabelType.I_LT_BAR_CABLE, "CatiaCable"); } forDeadLoadsBars.Add(barId); b.Id = barId; //b.RobotStart = robStart; //b.RobotEnd = robEnd; //b.StressAxial = 0.0; barId++; } }