- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have the following model:

If I run an add-in with the following code (where s is the RobotStructure and server is a RobotBarServer):
selBars = s.Selections.Get(IRobotObjectType.I_OT_BAR);
var bars = new List<IRobotBar>();
for (int i = 1; i <= sel.Count; i++)
{
IRobotDataObject v = server.Get(selBars.Get(i)); //this is where the error occurs (see below)
if(v as IRobotBar != null)
bars.Add(v as IRobotBar);
}
return bars;while only the two bars are selected, I get a list containing both of these bars. sel.Count equals 2. And the function works fine.
If, however, I run that code with the entire model selected (beams, nodes and geometrical objects), sel.Count equals 5. Going through the method, I get both bars and then an error on the indicated line. Obviously the geometrical objects are being included in the selection, which implies they also have IRobotObjectType.I_OT_BAR. However, they aren't contained in the RobotBarServer, which is overflowing since I'm probably asking for bar 10, 11 or 12 (the indices of the geom. objects), which don't exist.
Trying a renumbering, I've noticed that bars and geom. objects share a numbering system (if I change bar 2 to 11, geom. object 11 becomes 2), so I could do a test with server.Exist(), but I'd like to know if there's a simpler way to do it. Is there?
Solved! Go to Solution.
