Community
Hi there,
I'm working on an optimisation algorithm using robot steel design. The optimisation need to run a series of iterations including calculating the structure and chanding sections according to the results.
The first attemt of writing the algorithm seems promising and is still pretty basic, but I notice that the section changes is very time demanding.
Any suggestions to what I might be doing wrong?
Thanks in advance,
//Initialise robot RobotApplication robotApp = null; for (int try_count = 0; try_count < 5; try_count++) { try { robotApp = new RobotApplication(); if (robotApp != null) { System.Console.WriteLine("Robot application found: " + robotApp.Project.Name); break; } } catch { robotApp = null; System.Threading.Thread.Sleep(100); // Sleep for 1/10 second to allow Robot to wake up } } if (robotApp == null) { System.Windows.Forms.MessageBox.Show("ERROR : Unable to open an instance of Robot\nRobot needs to be installed on your machine for this function to work"); } IRobotStructure robotStructure = robotApp.Project.Structure; IRDimServer rDimServer; RDimStream rDimStream; IRDimCalcEngine rDimCalcEngine; rDimServer = (IRDimServer)robotApp.Kernel.GetExtension("RDimServer"); rDimStream = rDimServer.Connection.GetStream(); rDimServer.Mode = IRDimServerMode.I_DSM_STEEL; rDimCalcEngine = rDimServer.CalculEngine; IRDimCalcParam rDimCalcParam; rDimCalcParam = rDimCalcEngine.GetCalcParam(); rDimStream.WriteText("2"); rDimCalcParam.SetLoadsList(rDimStream); rDimStream.Clear(); //Populate section list List<string> sectionNames = new List<string>(); IRobotNamesArray inames = robotApp.Project.Structure.Labels.GetAvailableNames(IRobotLabelType.I_LT_BAR_SECTION); for (int i = 1; i < inames.Count; ++i) { sectionNames.Add(inames.Get(i)); } sectionNames.Sort(); for (int i = 0; i < sectionNames.Count; ++i) { System.Console.WriteLine(sectionNames[i]); } int numIter = 5; for (int iter = 0; iter < numIter; iter++) { //Calculate RobotCalcEngine calcEngine = robotApp.Project.CalcEngine; calcEngine.Calculate(); rDimCalcEngine.SetCalcParam(rDimCalcParam); rDimCalcEngine.Solve(null); //Get results IRDimAllRes rDimAllRes; IRDimAllResObjectType rDimAllResObjectType; int usrNo; rDimAllRes = rDimCalcEngine.Results(); rDimAllResObjectType = rDimAllRes.ObjectsType; int objectCount = rDimAllRes.ObjectsCount; for (int i = 0; i < objectCount; i++) { usrNo = rDimAllRes.ObjectUsrNo(i); IRDimDetailedRes rDimDetailedRes; rDimDetailedRes = (IRDimDetailedRes)rDimAllRes.Get(usrNo); double ratio = rDimDetailedRes.Ratio; //Toggle sections IRobotBar robotBar; IRobotLabel robotLabel; robotBar = (IRobotBar)robotStructure.Bars.Get(usrNo); robotLabel = robotBar.GetLabel(IRobotLabelType.I_LT_BAR_SECTION); IRobotBarSectionData robotBarSectionData; robotBarSectionData = (IRobotBarSectionData)robotLabel.Data; string sectionName = robotBarSectionData.Name; int sectionIndex = sectionNames.IndexOf(sectionName); if (ratio > 1) { if (sectionIndex != sectionNames.Count - 1) robotBar.SetSection(sectionNames[sectionIndex + 1], false); } else if (ratio < 1) { if (sectionIndex != 0) robotBar.SetSection(sectionNames[sectionIndex - 1], false); } } }
Check this thread:
Find there files. This is the fastest access to robot thru API.
I will check your code later.