Robot Structural Analysis Forum
Welcome to Autodesk’s Robot Structural Analysis Forums. Share your knowledge, ask questions, and explore popular Robot Structural Analysis topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

API - Error with RobotBarServer and geometrical objects

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
pnacht
276 Views, 3 Replies

API - Error with RobotBarServer and geometrical objects

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?

Tags (2)
3 REPLIES 3
Message 2 of 4
Rafal.Gaweda
in reply to: pnacht


 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
Message 3 of 4
pnacht
in reply to: Rafal.Gaweda

Just to be clear, instead of using List<IRobotBar>, I should use RobotBarCollection?
Message 4 of 4
Rafal.Gaweda
in reply to: pnacht

Yes.


Rafal Gaweda

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report