Global transformation of a selected nested face
-
Hi,
Is there a way to find out a global transformation of a selected face?
When I try face.parent I get a component (group) definition.
Is there a way to get an instance inside which the face has been selected?Thanks
Tomasz -
I have found a possible workaround through ray-casting, but I think it is valid only in a new tool and won't work well with a basic selection. It would be also awkward to cast a ray few milimeters off the face in an opposite direction to a normal .. hoping to hit the face.. not an opening .
It would be extremely nice to have a Ruby method Sketchup.active_model.active_entity (not entities) which would return an active group or component instance.
-
I think you need to you multiply the transformation of the given instance/group by what you want the contained face to be 'moved' to ... and it should then match your aspirations [tran1 * tran2... ?]...
.
-
I think Tomasz needs to get the instance of the face's container - a Group in this case - in order to get it's transformation to which the face's normal is relative to. And I don't know how to do it, but I haven't given it much effort.
-
-
I am not totally sure about this but it might not be possible. I believe that you cant actually select a face in an instance. What you are really doing is selecting a face in the definition. So as far as Sketchup is concerned all instances have that face selected.
There might be a work around depending on what you are trying to do.
-
To find the instance of a group that is given by its definition that you have got through parent use
face.parent.instances[0]
- there's only one instance of a group definition - groups are unique !
.
-
Groups are usually unique. Sometimes they are not. Count instances in the definition to be sure and then call make_unique.
-
Thanks for all help. It is rather an academic dilemma for me. I wanted to be sure it is valid to put it on Ruby API wish-list.
From what you have all written there is no way to find out where an user is in a tree of transformations. Only if an user selects an instance, not a face inside a component, it is possible to find out all parents of an instance and - as a result, calculate global coordinates of a all vertices in a component. Am I right?
It would be very useful if SU could return an array of all parent entities as it can do when using ray-casting method - simply to provide current location within outliner tree.
-
It depends on what you mean by "where the user is". If your user has just clicked on something you can find out the top level instance and then figure out the transform of the object in that instance.
If your user has "opened" the object its a little trickier but you can find the top instance through an observer.
Advertisement