API - Error with RobotBarServer and geometrical objects

API - Error with RobotBarServer and geometrical objects

Anonymous
Not applicable
595 Views
3 Replies
Message 1 of 4

API - Error with RobotBarServer and geometrical objects

Anonymous
Not applicable

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?

0 Likes
Accepted solutions (1)
596 Views
3 Replies
Replies (3)
Message 2 of 4

Rafal.Gaweda
Autodesk Support
Autodesk Support
Accepted solution

 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.

 

Wrong. Need to be corrected

 

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.

 

Use such code:

 

    Dim BarSel As RobotSelection
    Set BarSel = RobApp.Project.Structure.Selections.Get(I_OT_BAR)

    
    Dim Bars As RobotBarCollection
    Set Bars = RobApp.Project.Structure.Bars.GetMany(BarSel)

 and Bars.Count will return only number of bars and make loop in Bars Collection.

 



Rafal Gaweda
0 Likes
Message 3 of 4

Anonymous
Not applicable
Just to be clear, instead of using List<IRobotBar>, I should use RobotBarCollection?
0 Likes
Message 4 of 4

Rafal.Gaweda
Autodesk Support
Autodesk Support
Yes.


Rafal Gaweda
0 Likes