Make copies of a bar with API

Make copies of a bar with API

Leandro_Azevedo
Contributor Contributor
873 Views
8 Replies
Message 1 of 9

Make copies of a bar with API

Leandro_Azevedo
Contributor
Contributor

Greetings,

I've been making a add-in for Robot to move a selected structure based on a origin referential frame and a destination referential frame (allowing to translate+rotate+scale in a single instruction). I got this part working, but now I want to add a option to copy instead of moving.

 

I can create new bars with Bars.Create but then I have to set all properties equal to the original bars, and also I have to Get the new bar from model after creating it. Copying a bar seems to be a simple task, but can't find examples of doing this directly. Any ideas to accomplish this in any simple way?

 

Here's my code (C#) at the moment, where "Transform()" gives the new coordinates, and "newfrom" keeps track of the old and new points, "Rnodes" and "Rbars" are RobotNodeCollection and RobotBarCollection respectively.

 

//list of original and translated points
Dictionary<int, int> newfrom = new Dictionary<int, int>();

// node creation
for (int i = 1; i <= Rnodes.Count; i++)
{
    RobotNode no = Rnodes.Get(i);
    Vector3 result = Transform(new Vector3((float)no.X, (float)no.Y, (float)no.Z));
    int id = robapp.Project.Structure.Nodes.FreeNumber;
    robapp.Project.Structure.Nodes.Create(id, result.X, result.Y, result.Z);
    newfrom.Add(no.Number, id);
}
// bar creation
for (int i = 1; i <= Rbars.Count; i++)
{
    RobotBar bar = Rbars.Get(i);

    int id = robapp.Project.Structure.Bars.FreeNumber;
    int node1 = newfrom[bar.StartNode];
    int node2 = newfrom[bar.EndNode];

    robapp.Project.Structure.Bars.Create(id, node1, node2);
    RobotBar newbar = (RobotBar)robapp.Project.Structure.Bars.Get(id);
}

 

0 Likes
Accepted solutions (2)
874 Views
8 Replies
Replies (8)
Message 2 of 9

Romanich
Mentor
Mentor
Accepted solution

Hi @Leandro_Azevedo ,

 

Sorry for the offtopic, but it seems that the possibility to translate+rotate+scale in a single instruction is already implemented in Robot:

Edit >Complex Edit

Romanich_0-1694626097614.png

 

Do you find the posts helpful? "LIKE" these posts!
Have your question been answered successfully? Click 'ACCEPT SOLUTION' button.

Roman Zhelezniak

Robot Evangelist & Passionate Civil Structural Engineer

LinkedIn | Robot & Хобот | App Store for Robot
EESignature


0 Likes
Message 3 of 9

Stephane.kapetanovic
Mentor
Mentor

hi @Leandro_Azevedo 

firstly, have you tried RobotStructureEditTools methods ?

Stephanekapetanovic_0-1695095496474.png

Best Regards

Stéphane Kapetanovic

Did you find this post helpful? If it gave you one or more solutions,
don't forget to accept the solution and leave a < like !
EESignature
0 Likes
Message 4 of 9

Leandro_Azevedo
Contributor
Contributor

Thanks, I didn't know about that tool, but still lacks a bit of the functionality I need

0 Likes
Message 5 of 9

Leandro_Azevedo
Contributor
Contributor

I did took a look into it, however to use those tools in my program I have 2 major cons:

 - I would need to break my complex translation into the available tools, which would require additional code to determine the mirror planes and rotation axis in 3D space

 - I still lack some of the functionality I want, such as scaling just in one direction

0 Likes
Message 6 of 9

Stephane.kapetanovic
Mentor
Mentor

hi @Leandro_Azevedo 

At the first message it seemed to me that you were looking to create a copy function but after discussing you were also looking for an intermediate transformation (mirror, stretch, i dont't know). Do you have a view to explain all? Why two loops (Nodes + Bars)?

Best Regards

Stéphane Kapetanovic

Did you find this post helpful? If it gave you one or more solutions,
don't forget to accept the solution and leave a < like !
EESignature
0 Likes
Message 7 of 9

Leandro_Azevedo
Contributor
Contributor

I've attached the MainWindow layout and an example case

(scale factor is determined by the lengths of vectors in that direction, blank values are assumed as the global directions)

 

Created two loops because there may be isolated nodes that would not get copied if I looped only through bars, and also I'm not sure how robot will handle nodes being placed on the same coordinates (by copying bars with common nodes one at a time)

 

EDIT: Re-uploaded the example because of wrong values

0 Likes
Message 8 of 9

Stephane.kapetanovic
Mentor
Mentor
Accepted solution

hi @Leandro_Azevedo 

as @Romanich said, this feature already exists, follow these links (Geometry Manipulation)  

Best Regards

 

Stéphane Kapetanovic

Did you find this post helpful? If it gave you one or more solutions,
don't forget to accept the solution and leave a < like !
EESignature
0 Likes
Message 9 of 9

Leandro_Azevedo
Contributor
Contributor

Hi, exploring around your suggestions and links I found this feature I didn't know about (Transformation of Coordinate System) that does precisely what I want. Still a shame that one can't simply do something like

Rbars.Add(FreeNumber, Bar[1].Copy)

 

Anyway, Thanks @Stephane.kapetanovic and @Romanich 

 

0 Likes