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.copymethod 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.copymethod 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.definitionmethod
, 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.parentComponentDefinition
just as the much snappier methoddefn = instance.definitiondoes for a component-instance !
The second argument of theentities.add_instance(defn, **tr**)is the transformation used to place/manipulate the new instance...
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better π
Register LoginAdvertisement