Find the position of a group in the active context
-
Hi, I'm trying to find the position of a group in the active context, relative to the coordinate system of the group that it contains (which itself can be contained within other groups), this picture illustrates the situation
You may also need to do this but with components. Really, I do not find the way to accomplish what I need, I appreciate your help
(google translator).
-
A recent discussion might help
-
thanks for replying, I saw this link, unfortunately I still do not understand how to solve my problem
-
The transformation of a sub-group will be relative to its parent so the sub-groups.transformation.origin will be the dx,dy,dz relative to the container group.
For example your model contains a group which contains another group then the following code would find the most embedded group and output its transformation.origin to the Ruby Console.
mod = Sketchup.active_model ent = mod.active_entities sel = mod.selection grps=[];tran=[] grps<<ent.grep(Sketchup;;Group)[0] tran<<grps[0].transformation begin fnd=false grps[-1].entities.each{|e| if e.class==Sketchup;;Group grps<<e;tran<<e.transformation fnd=true;break end } end while fnd puts grps[-1].transformation.origin
-
Sdmitch thank you very much, unfortunately the problem persists when I'm in the active context, I'm trying something with this
mod = Sketchup.active_model path = mod.active_path tr1 = Geom;;Transformation.new([0,0,0],[1,0,0],[0,1,0]) if path path.each{|entity| tr2 = entity.local_transformation tr1 = tr1*tr2 } end tr1.origin
It works, but to play around with this in the least expected moment this fails. If it always worked, I would do something like this then
mod = Sketchup.active_model sel = mod.selection path = mod.active_path tr1 = Geom;;Transformation.new([0,0,0],[1,0,0],[0,1,0]) if path path.each{|entity| tr2 = entity.local_transformation tr1 = tr1*tr2 } end origin_parent = Geom;;Vector3d.new(tr1.origin.to_a) ejex_o = sel[0].transformation.xaxis ejey_o = sel[0].transformation.yaxis center = sel[0].local_bounds.center tr3 = Geom;;Transformation.new([0,0,0], ejex_o, ejey_o) center_tr = Geom;;Vector3d.new((center.transform tr3).to_a) origin_group = Geom;;Vector3d.new(sel[0].transformation.origin.to_a) point = origin_group - origin_parent + center_tr point_tr = point.transform tr1.inverse
here I have gained the center of the group with respect to the coordinate system of the parent in the active context. The problem is that it only works well sometimes,
I do not understand how to fix this
(google translator) -
I solved the problem, the key was to use "mod.edit_transform.origin"
I leave the code in case anyone needs it one daymod = Sketchup.active_model sel = mod.selection parert_origin = mod.edit_transform.origin entity_origin = sel[0].transformation.origin distance = entity_origin-parert_origin tr = mod.edit_transform.inverse distance.transform tr
Advertisement