Get instance parent of selected entity
-
If a user has entered a group and selected say an edge - I want to get the parent of the selected edge ie the group
Typing in the ruby console
Sketchup.active_model.selection[0].parentresponds with #Sketchup::ComponentDefinition:0xd3390f0 which is not the instance of the group
What I need to get is the transformation of the containing group.
Is there a way to get a handle to the group instance from the selection?
Thanks
BillW
-
groupsdefinition.instances[0]
should return the instance of the group. Note: to avoid a glitch that's not yet fixed with copied-but-unedited groups sharing the same definition, I suggest you use group.make_unique to help too - in some circumstances - might be irrelevant if you are editing that group as that will automatically make it unique ? ...
-
Check out this method. It sounds like it might work, though I've never used it:
http://code.google.com/apis/sketchup/docs/ourdoc/model.html#edit_transform
@unknownuser said:
Returns the transformation of the current component edit session. If a user has double-clicked to edit a component's geometry, this will return the transformation of that component, relative to its parent's origin. This allows one to correctly calculate "local" transformations of a given entity regardless of whether the user is in edit mode.
but its only available in SU 7.0 (and up). So it might mot help if you know your developing a script that will be run in SU version 6.
-
Assuming you want at least v6 AND 7 compatibility then this should return the transformation of the instance of the group containing the selected edge.
edge.parent.instances[0].transformation
???
-
Thanks both again
I tried a different tack originally with an add_group/explode combo but TIG the instances option worked perfectly.
Chris as I am disallowing component edit sessions for the time being and I am coding for SU 6 upwards, I will bear in mind Model.edit_transform for the future.
BillW
Advertisement