Ruby Equivalent of Move/Copy
-
Hey all.
I have a general understand of how to move entities using transformations.
But here's what I don't know how to do.
I have a group.
group_shell=model.active_entities.add_group() ents=group_shell.entities points_box=[[0,0,0],[5,0,0],[5,10,0],[0,10,0]] face_box=ents.add_face(points_box) face_box.pushpull(-20)
I'd like to make a copy of that group and move it to a different location. (I want two identical boxes sitting next to each other)
(yes, it's more complicated than just a box )
That's it.
Any hints?
Thanks!
Derek -
kybasche,
group_shell=model.active_entities.add_group() ents=group_shell.entities points_box=[[0,0,0],[5,0,0],[5,10,0],[0,10,0]] face_box=ents.add_face(points_box) face_box.pushpull(-20) group_shell_copy=group_shell.copy#create a copy tr=Geom;;Transformation.new([10,0,0])#copy location group_shell_copy.transform! tr
-
Brilliant!!
Thanks sdmitch.
-
One of the problems with using the standard
group.copy
method is that there are a few rogue scripts out there that mess with the function because they ill-advisedly change built-in classes/methods or have poorly formed observers etc - e.g. SketchyPhysics and DrivingDimensions... As some of these are popular it's best to avoid the.copy
method in a distributed script, where you have no control over what other tools the user has installed...
I forgot and had to recast SuperDrape the other day and I also remade Mirror a while ago too.
The alternative way produces the same result...
group_copy = group.copy
becomes
group_copy = group.parent.entities.add_instance(group.entities.parent, group.transformation)
I know it's a lot more convoluted BUT it does the same thing and doesn't seem to have issues with other scripts so much
In you case you can do the [predefined] transformation as you add the instance
group_copy = group.parent.entities.add_instance(group.entities.parent, tr)
-
TIG, Thanks for the info. As many times that I have searched through the Ruby API Document, I never saw that .add_instance could be applied to groups. It's always a good day when you learn something new.
-
You can only use
entities.add_instance()
of adefinition
, BUT there's no built ingroup.definition
method , BUT all components, groups and images are all just types of instances of a definition.
To find a group's definition you have to find its entities' parent which is the definition - so
defn = group.entities.parent
ComponentDefinition
just as the much snappier methoddefn = instance.definition
does for a component-instance !
The second argument of theentities.add_instance(defn, **tr**)
is the transformation used to place/manipulate the new instance...
Advertisement