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); }
public static double[,] Run_analysis() { robApp.Project.CalcEngine.Calculate(); results = robApp.Project.Structure.Results.Bars.Forces; double[,] a = new double[6, Genome.towerBar_cnt]; // for (int k = 0; k < 4; k++) //para 5 casos de carga // { for (int i = 0; i < Genome.towerBar_cnt; i++) { IRobotBar current_bar = (IRobotBar)robApp.Project.Structure.Bars.Get(i + 1); a[0, i] = i + 1; a[1, i] = current_bar.Length; a[2, i] = Max(results.Value(i + 1, 1, 0).FX * -1.0, results.Value(i + 1, 1, 0.5).FX * -1.0, results.Value(i + 1, 1, 1).FX * -1.0) / 1000; //converter N para Kn *-1 porque comp = + no robot // a[3, i] = Max(results.Value(i + 1, 1, 0).MY, results.Value(i + 1, 1, 0.5).MY, results.Value(i + 1, 1, 1).MY) / 1000; //N/m -> kN/m // a[4, i] = Max(results.Value(i + 1, 1, 0).MZ, results.Value(i + 1, 1, 0.5).MZ, results.Value(i + 1, 1, 1).MZ) / 1000; //a[5, i] = 1; //remover(era para o V) // para comparar multiplos load cases for (int k = 2; k < 5; k++) { double temp = Max(results.Value(i + 1, k, 0).FX * -1.0, results.Value(i + 1, k, 0.5).FX * -1.0, results.Value(i + 1, k, 1).FX * -1.0) / 1000; if (a[2, i] < 0 && temp < 0) // se a verificação e de buckling { a[2, i] = Math.Min(a[2, i], temp); } else if (a[2, i] < 0 && temp > 0) { if (temp * 0.4 > Math.Abs(a[2, i])) { a[2, i] = temp; } // so se força de traçao for muito maior é que substitui força de comp } else if (a[2, i] > 0 && temp < 0) { if (Math.Abs(temp) > 0.4 * a[2, i]) { a[2, i] = temp; } // so se a F tração for muito grande é que nao é subst por comp } else if (a[2, i] > 0 && temp > 0) { a[2, i] = Math.Max(temp, a[2, i]); } } } return(a); //[rbt_bar_num,Lenght,Fx,My,Mz] }
public void test() { RobotApplication appRSA = new RobotApplication(); getMaterialNameListRSA(appRSA); getBarSectionNamesRSA(appRSA); RobotStructure structureRSA = appRSA.Project.Structure; RobotBarServer barsRSA = structureRSA.Bars; RobotNodeServer nodesRSA = structureRSA.Nodes; RobotObjObjectServer objRSA = structureRSA.Objects; RobotLabelServer labelsRSA = appRSA.Project.Structure.Labels; //Определение выборок выделенных в модели объектов RobotSelection barSel = structureRSA.Selections.Get(IRobotObjectType.I_OT_BAR); RobotSelection plateSel = structureRSA.Selections.Get(IRobotObjectType.I_OT_PANEL); RobotSelection holesSel = structureRSA.Selections.Get(IRobotObjectType.I_OT_GEOMETRY); RobotBarCollection barsMany = (RobotBarCollection)barsRSA.GetMany(barSel); RobotObjObjectCollection platesMany = (RobotObjObjectCollection)objRSA.GetMany(plateSel); IRobotBar barRSA = barsMany.Get(3); IRobotObjObject plate = platesMany.Get(1); IRobotLabel labelPlate = plate.GetLabel(IRobotLabelType.I_LT_PANEL_THICKNESS); RobotGeoPoint3DCollection defPoints = (RobotGeoPoint3DCollection)plate.Main.DefPoints; RobotGeoPoint3D pt1 = defPoints.Get(1); RobotGeoPoint3D pt2 = defPoints.Get(2); RobotGeoPoint3D pt3 = defPoints.Get(defPoints.Count); //IRobotGeoContour geoContour=(IRobotGeoContour)plate.Main.Geometry; //IRobotGeoObject geoObj=plate.Main.Geometry; IRobotLabel labelBar = barRSA.GetLabel(IRobotLabelType.I_LT_BAR_SECTION); RobotBarSectionData data = labelBar.Data; RobotBarSectionConcreteData cData = data.Concrete; double b = cData.GetValue(IRobotBarSectionConcreteDataValue.I_BSCDV_COL_B); double h = cData.GetValue(IRobotBarSectionConcreteDataValue.I_BSCDV_COL_H); double l1 = cData.GetValue(IRobotBarSectionConcreteDataValue.I_BSCDV_COL_L1); double l2 = cData.GetValue(IRobotBarSectionConcreteDataValue.I_BSCDV_COL_L2); double h1 = cData.GetValue(IRobotBarSectionConcreteDataValue.I_BSCDV_COL_H1); double h2 = cData.GetValue(IRobotBarSectionConcreteDataValue.I_BSCDV_COL_H2); double de = cData.GetValue(IRobotBarSectionConcreteDataValue.I_BSCDV_COL_DE); double alfa = barRSA.Gamma; }
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; } } }
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; }
/// <summary> /// Extract the straight-line geometry of a Robot bar as a Nucleus line /// </summary> /// <param name="bar">The bar to extract geometry for</param> /// <param name="structureNodes">The full collection of nodes within the structure that contains the bar</param> /// <returns></returns> public static Line GeometryOf(IRobotBar bar, RobotNodeServer structureNodes) { return(new Line(PositionOf(bar.Start, structureNodes), PositionOf(bar.End, structureNodes))); }
}//loadProfileDatabase //Divide columns into a number of bars //Reference: https://forums.autodesk.com/t5/robot-structural-analysis-forum/api-divide-bars/m-p/4422193#M16921 public void divideColumns(int divisionNumber, string section) { int firstIsolatedNode = iRobotApp.Project.Structure.Nodes.FreeNumber; //First new created node int freeNodeNumber = firstIsolatedNode; //Add columns to the selection foreach (Bar bar in bars) { if (bar.type == MemberType.Column) { IRobotBar robotBar = (RobotBar)iRobotApp.Project.Structure.Bars.Get(bar.id); IRobotNode startNode = (RobotNode)iRobotApp.Project.Structure.Nodes.Get(bar.startNode.id); IRobotNode endNode = (RobotNode)iRobotApp.Project.Structure.Nodes.Get(bar.endNode.id); //Console.WriteLine("freeNodeNumber: " + freeNodeNumber); //Bar vector double vx, vy, vz, vl; vx = endNode.X - startNode.X; vy = endNode.Y - startNode.Y; vz = endNode.Z - startNode.Z; //Vector length vl = Math.Sqrt(Math.Pow(vx, 2) + Math.Pow(vy, 2) + Math.Pow(vz, 2)); //Normalization vx /= vl; vy /= vl; vz /= vl; //distance between nodes double distance = vl / divisionNumber; //Adding new nodes for (int j = 0; j < divisionNumber - 1; j++) { //Add to the list of nodes //Add a new node Node node = new Node(freeNodeNumber, startNode.X + (j + 1) * vx * distance, startNode.Y + (j + 1) * vy * distance, startNode.Z + (j + 1) * vz * distance); //Console.Write("startNode.X = " + startNode.X); //Console.Write(" startNode.Y = " + startNode.Y); //Console.WriteLine(" startNode.Z = " + startNode.Z); //Console.WriteLine("vx: " + vx + " vy: " + vy + " vz: " + vz + " vl: " + vl); //Console.WriteLine("Node id: " + node.id + " x: " + node.xCoord + " y: " + node.yCoord + " z: " + node.zCoord); nodes.Add(node); //Add a node to the structure iRobotApp.Project.Structure.Nodes.Create(freeNodeNumber, node.xCoord, node.yCoord, node.zCoord); freeNodeNumber++; } } } //Creating aditional bars int numberOfBars = bars.Count + 1; int barIndex = numberOfBars; //Console.WriteLine("Number of bars: " + numberOfBars); int index = firstIsolatedNode; //Console.WriteLine("firstIsolatedNode: " + index); for (int i = 0; i < (divisionNumber - 1); i++) { //Finding the nodes for a line of bars IRobotNode iNode1 = (RobotNode)iRobotApp.Project.Structure.Nodes.Get(index); //Console.WriteLine("Node 1 - " + iNode1.Number); IRobotNode iNode2 = (RobotNode)iRobotApp.Project.Structure.Nodes.Get((index + 2)); //Console.WriteLine("Node 2 - " + iNode2.Number); IRobotNode iNode3 = (RobotNode)iRobotApp.Project.Structure.Nodes.Get((index + 4)); //Console.WriteLine("Node 3 - " + iNode3.Number); IRobotNode iNode4 = (RobotNode)iRobotApp.Project.Structure.Nodes.Get((index + 6)); //Console.WriteLine("Node 4 - " + iNode4.Number); Node node1 = new Node(iNode1.Number, iNode1.X, iNode1.Y, iNode1.Z); nodes.Add(node1); Node node2 = new Node(iNode2.Number, iNode2.X, iNode2.Y, iNode2.Z); nodes.Add(node2); Node node3 = new Node(iNode3.Number, iNode3.X, iNode3.Y, iNode3.Z); nodes.Add(node3); Node node4 = new Node(iNode4.Number, iNode4.X, iNode4.Y, iNode4.Z); nodes.Add(node4); barIndex += i; Bar bar1 = new Bar(barIndex, node1, node2, MemberType.Bar, section); bars.Add(bar1); //Console.WriteLine("Bar id: " + bar1.id + ", first node id: " + bar1.startNode.id + ", last node id: " + bar1.endNode.id); barIndex += 1; Bar bar2 = new Bar(barIndex, node1, node3, MemberType.Bar, section); bars.Add(bar2); //Console.WriteLine("Bar id: " + bar2.id + ", first node id: " + bar2.startNode.id + ", last node id: " + bar2.endNode.id); barIndex += 2; Bar bar3 = new Bar(barIndex, node2, node4, MemberType.Bar, section); //Console.WriteLine("Bar id: " + bar3.id + ", first node id: " + bar3.startNode.id + ", last node id: " + bar3.endNode.id); bars.Add(bar3); barIndex += 3; Bar bar4 = new Bar(barIndex, node3, node4, MemberType.Bar, section); bars.Add(bar4); //Console.WriteLine("Bar id: " + bar4.id + ", first node id: " + bar4.startNode.id + ", last node id: " + bar4.endNode.id); index += 1; } index += 6; barIndex += 1; for (int i = 0; i < (divisionNumber - 1); i++) { //Finding the nodes for a line of bars IRobotNode iNode1 = (RobotNode)iRobotApp.Project.Structure.Nodes.Get(index); //Console.WriteLine("Node 1 - " + iNode1.Number); IRobotNode iNode2 = (RobotNode)iRobotApp.Project.Structure.Nodes.Get((index + 2)); //Console.WriteLine("Node 2 - " + iNode2.Number); IRobotNode iNode3 = (RobotNode)iRobotApp.Project.Structure.Nodes.Get((index + 4)); //Console.WriteLine("Node 3 - " + iNode3.Number); IRobotNode iNode4 = (RobotNode)iRobotApp.Project.Structure.Nodes.Get((index + 6)); //Console.WriteLine("Node 4 - " + iNode4.Number); Node node1 = new Node(iNode1.Number, iNode1.X, iNode1.Y, iNode1.Z); nodes.Add(node1); Node node2 = new Node(iNode2.Number, iNode2.X, iNode2.Y, iNode2.Z); nodes.Add(node2); Node node3 = new Node(iNode3.Number, iNode3.X, iNode3.Y, iNode3.Z); nodes.Add(node3); Node node4 = new Node(iNode4.Number, iNode4.X, iNode4.Y, iNode4.Z); nodes.Add(node4); barIndex += i; Bar bar1 = new Bar(barIndex, node1, node2, MemberType.Bar, section); bars.Add(bar1); //Console.WriteLine("Bar id: " + bar1.id + ", first node id: " + bar1.startNode.id + ", last node id: " + bar1.endNode.id); barIndex += 1; Bar bar2 = new Bar(barIndex, node1, node3, MemberType.Bar, section); bars.Add(bar2); //Console.WriteLine("Bar id: " + bar2.id + ", first node id: " + bar2.startNode.id + ", last node id: " + bar2.endNode.id); barIndex += 2; Bar bar3 = new Bar(barIndex, node2, node4, MemberType.Bar, section); //Console.WriteLine("Bar id: " + bar3.id + ", first node id: " + bar3.startNode.id + ", last node id: " + bar3.endNode.id); bars.Add(bar3); barIndex += 3; Bar bar4 = new Bar(barIndex, node3, node4, MemberType.Bar, section); bars.Add(bar4); //Console.WriteLine("Bar id: " + bar4.id + ", first node id: " + bar4.startNode.id + ", last node id: " + bar4.endNode.id); index += 1; } addRobotBars(numberOfBars - 1, null, null, null, section); }//divideColumns
private void button1_Click(object sender, EventArgs e) { Excel.Application xlApp = new Excel.Application(); Excel.Workbook xlWorkbook = xlApp.Workbooks.Open(@"EXCELPATH...\excelFile.xlsx", 0, false); Excel.Sheets xlSheets = xlWorkbook.Worksheets; string currentSheet = "Sheet1"; Excel.Worksheet xlWorksheet = (Excel.Worksheet)xlSheets.get_Item(currentSheet); IRobotApplication robotApp = new RobotApplication(); IRobotLabelServer lab_serv = robotApp.Project.Structure.Labels; progressBar1.Value = 0; progressBar1.Maximum = 151; progressBar1.Minimum = 0; progressBar1.Step = 1; for (int i = 1; i < 152; i++) { string secName = xlWorksheet.Cells[i + 1, 1].Value.ToString(); double secAx = double.Parse(xlWorksheet.Cells[i + 1, 2].Value.ToString()); double secIx = double.Parse(xlWorksheet.Cells[i + 1, 3].Value.ToString()); double secIy = double.Parse(xlWorksheet.Cells[i + 1, 4].Value.ToString()); double secIz = double.Parse(xlWorksheet.Cells[i + 1, 5].Value.ToString()); double secVy = double.Parse(xlWorksheet.Cells[i + 1, 6].Value.ToString()); double secVpy = double.Parse(xlWorksheet.Cells[i + 1, 7].Value.ToString()); double secVz = double.Parse(xlWorksheet.Cells[i + 1, 8].Value.ToString()); double secVpz = double.Parse(xlWorksheet.Cells[i + 1, 9].Value.ToString()); IRobotLabel sec = lab_serv.Create(IRobotLabelType.I_LT_BAR_SECTION, secName); IRobotBarSectionData data = sec.Data; data.Type = IRobotBarSectionType.I_BST_STANDARD; data.ShapeType = IRobotBarSectionShapeType.I_BSST_UNKNOWN; data.SetValue(IRobotBarSectionDataValue.I_BSDV_AX, secAx); data.SetValue(IRobotBarSectionDataValue.I_BSDV_IX, secIx); data.SetValue(IRobotBarSectionDataValue.I_BSDV_IY, secIy); data.SetValue(IRobotBarSectionDataValue.I_BSDV_IZ, secIz); data.SetValue(IRobotBarSectionDataValue.I_BSDV_VY, secVy); data.SetValue(IRobotBarSectionDataValue.I_BSDV_VPY, secVpy); data.SetValue(IRobotBarSectionDataValue.I_BSDV_VZ, secVz); data.SetValue(IRobotBarSectionDataValue.I_BSDV_VPZ, secVpz); lab_serv.Store(sec); IRobotBar bar = (IRobotBar)robotApp.Project.Structure.Bars.Get(i); bar.SetLabel(IRobotLabelType.I_LT_BAR_SECTION, secName); progressBar1.PerformStep(); } Marshal.FinalReleaseComObject(xlWorksheet); Marshal.FinalReleaseComObject(xlSheets); xlWorkbook.Close(false); Marshal.FinalReleaseComObject(xlWorkbook); xlApp.Quit(); Marshal.FinalReleaseComObject(xlApp); MessageBox.Show("All the profiles have been applied!", "Work done !", MessageBoxButtons.OK); }
/// <summary> /// Add a new Bar entry to this mapping table /// </summary> /// <param name="element"></param> /// <param name="bar"></param> public void Add(LinearElement element, IRobotBar bar) { Add(BarCategory, element.GUID, bar.Number.ToString()); }
/// <summary> /// Get the Nucleus element, if any, mapped to the ID of the specified robot bar /// </summary> /// <param name="bar"></param> /// <param name="model"></param> /// <returns></returns> public LinearElement GetMappedLinearElement(IRobotBar bar, Model.Model model) { return(GetMappedLinearElement(bar.Number, model)); }
public void DoCommand(int cmd_id) { IRobotStructure structure = robot_app.Project.Structure; // Get bars and nodes IRobotCollection bars = structure.Bars.GetAll(); IRobotCollection nodes = structure.Nodes.GetAll(); // Create 3D points at nodes var points = new Dictionary <int, Point3D>(); for (int i = 1; i <= nodes.Count; i++) { var node = (IRobotNode)nodes.Get(i); points[i] = new Point3D(node.X, node.Y, node.Z); } // Create 3D vectors for each bar and index of bars connected to a node var vectors = new Dictionary <int, Vector3D>(); var vect_by_pt = new DefaultDict <int, List <Vector3D> >(); for (int i = 1; i <= bars.Count; i++) { var bar = (IRobotBar)bars.Get(i); var start_pt = points[bar.StartNode]; var end_pt = points[bar.EndNode]; vectors[i] = end_pt - start_pt; vect_by_pt[bar.StartNode].Add(vectors[i]); vect_by_pt[bar.EndNode].Add(vectors[i]); } ; foreach (KeyValuePair <int, Vector3D> vector in vectors) { // `u` is the vector corresponding to the bar Vector3D u = vector.Value; UnitVector3D u_norm = u.Normalize(); int start = bars.Get(vector.Key).StartNode; // TODO: How about the other end? // Find the most orthogonal vector `v` Vector3D most_orth_v = u; double cur_min = 1; foreach (Vector3D x in vect_by_pt[start]) { UnitVector3D x_norm = x.Normalize(); double dot_prod = Math.Abs(u_norm.DotProduct(x_norm)); if (dot_prod < cur_min) { most_orth_v = x; cur_min = dot_prod; } } if (cur_min > 0.95) { continue; } var v = most_orth_v; var v_norm = v.Normalize(); // Vector `a` is vector a orthogonal to `u` in (u,v) plane Vector3D a = v - u_norm.DotProduct(v) * u; UnitVector3D a_norm = a.Normalize(); // Vector `c` is orthogonal to `u` in the global (X,Y) plane UnitVector3D c = u_norm.CrossProduct(UnitVector3D.ZAxis); // Vector `d` is orthogonal to `c` and `u` UnitVector3D d = c.CrossProduct(u_norm); // Calculate the angles of `a` with `d` and `c` Angle theta1 = a.AngleTo(d); Angle theta2 = a.AngleTo(c); // Calculate gamma from `theta1` and `theta2` Angle gamma = (theta2.Degrees < 90) ? theta1 : -theta1; double gamma_up = (gamma.Degrees < 0) ? gamma.Degrees + 90 : gamma.Degrees - 90; // Set `Gamma` attribute of bar IRobotBar bar = bars.Get(vector.Key); bar.Gamma = gamma_up; } // Redraw all views robot_app.Project.ViewMngr.Refresh(); }