Hierarchy question
-
I'm trying to build up a hierarchical object in ruby/ketchup using nested groups, and components where appropriate.
Most of the "add" operations seem to place things at the origin.
To put things in the proper places, I've been creating them inside a group,
then using the "transform_entities" method to translate and rotate the entities in the group.What's puzzling me is that when I apply transform_entities to the entities in the group, it works okay.
The objects go where I want them to.
I do something like create a few objects at the origin, rotate the group.entities to the desired orientation,
then translate the group.entities away from the origin.
Then, when I create a new (drawing) object inside the group, it doesn't appear at the origin. It appears at the translated origin that I thought was applied to each entity in the group. Why does the translation appear to be applied to new objects added to the group?Thanks for your help, or in directing me to the appropriate person/list.
Chelmite(P.S. One of my first programming jobs was in 1972, programming transformation matrices for a robotic arm at the Stanford AI Lab, so I'm very familiar with graphics concepts, but not necessarily with how they are implemented in SketchUp.)
-
@chelmite said:
Why does the translation appear to be applied to new objects added to the group?
Because the
transformation
is a property of the group (or component) instance, not the primitives within it's definition'sentities
collection, hence theorigin
is a property of thetransformation
.my_group_origin = my_group.transformation.origin()
TIG has written extensively on
transformation
, you can go to his profile page, and click the link to search his posts. (Search this forum for 'transformation' yields 71 pages of hits !!)Also keep in mind that a
Group
is (internally,) a special kind ofComponentInstance
, ie it has aComponentDefinition
(which appears it the model'sDefintionList
collection.)
Meaning thatgroup.entities
, is similar to callingcomponent_instance.definition.entities
(if you were dealing with a component instance instead of a group.) The collection of primitives returned bygroup.entities
, can also be accessed through the model'sDefintionList
collection. The reason for thegroup.entities
shortcut method is that often groups are used as singleton definitions (ie, they often have only one instance, but can have many more than one.) -
Edited the first paragraph of my reply (above,) to make it more clear that the
entities
collection, belongs to theComponentDefinition
, and not the instance (be they groups or components.)
Advertisement