Moving groups between groups with the API

I haven’t posted much to the Ruby API board lately, primarily because I don’t usually need to, most of my code is fairly established and I usually can find a sample within my code to massage a little and reuse it.

However, today I’ve come upon a programming problem I don’t think I’ve encountered before.

First I’m creating two groups within my parent group:

entities0 = maingroup.entities

dooronlygroup1 = entities0.add_group
entities01 = dooronlygroup1.entities

dooronlygroup2 = entities0.add_group
entities02 = dooronlygroup2.entities

I then create a group within “dooronlygroup1” that contains a bunch of geometry, I call this group “group1s”, I then copy it and mirror it, creating “group2s”:

group2s = group1s.copy
		
trmirror = Geom::Transformation.scaling([0,0,0], -1, 1, 1)
group2s = group2s.transform! trmirror

My problem is that the mirrored group “group2s” is naturally within the “dooronlygroup1” and I want to somehow move it into the “dooronlygroup2”. Is there a way to do this?

I can probably figure this out or even come up with a clever work around if I muck around with it long enough (a couple of hours), but I figure I would ask here first instead of wasting my time and beating my head against a brick wall, like I usually do.

You could do it this way…
You have the definition of group1s.
Use add_instance on that in the dooronlygroup2.entities using the group1s.transformation - call it group2s.
Take that group2s instance and apply your mirroring transformation etc.
If necessary use make unique on the new group group2s, otherwise it’s linked as a copy of the original group group1s…

3 Likes

What would be the difference in using add_instance or add_group?

This seems to work:

def1s = group1s.definition
trans1s = group1s.transformation
group2s = entities02.add_instance(def1s, trans1s)

Geom::Transformation.scaling([0,0,0], -1, 1, 1)
group2s = group2s.transform! trmirror

It doesn’t seem to need the make unique call, the resulting group appears to be unique.

add_group creates an empty group and creates a new definition for it. add_instance adds an instance, group or component, using as existing definition.

2 Likes

Tracking the documentation issue as GitHub 776.

2 Likes

Would be better as
group2s.transform!(trmirror)
The added ! changes the group anyway…

1 Like

I am only following what is documented in the API docs:

With the exclamation mark I never have understood why they just didn’t show the utilization like you have shown above.

Many methods have two versions, one without and one with an exclamation point. The one without a ! returns a new, modified object. The one with a ! modifies the original object and also returns it. I suppose the person writing the API doc thought this was a well-known convention so didn’t feel a need to explain it.

3 Likes