Get group location over Ruby Script
-
Hello everybody,
can somebody explain me, how i get the location of a group(In Sketchup.active_model) over a ruby script ? Currently, i get only the local position of the entities in the group(groups have a own axis of abscissas), but i need the global position. I hope, you-all understand my problem
Cu
Ossi01 -
Is the group in the active context? (
model.active_entities
? )
How are you obtaining the group? -
@ thomthom : Yes, the group is in model.active_entites and i obtaining the group. This isn't my Problem. But i get over Sketchup.active_model.active_entities[0].entities[1].end.position or Sketchup.active_model.active_entities[0].entities[1].start.position the local position of a edge(Start- and End-Vertex) in the group , not the global position in the whole model ! But i need the global position
-
Try
tr=group.transformation
to get the group's current position and then when you get the contents points transform! them by 'tr' - e.g.pt.transform!(tr)
If the group is not within themodel.entities
(as ingroup.parent != model
) you need to recursively apply the parent's parent's transformations until it is etc... using awhile parent != model ... end
loop ? -
@ossi01 said:
@ thomthom : Yes, the group is in model.active_entites and i obtaining the group. This isn't my Problem. But i get over Sketchup.active_model.active_entities[0].entities[1].end.position or Sketchup.active_model.active_entities[0].entities[1].start.position the local position of a edge(Start- and End-Vertex) in the group , not the global position in the whole model ! But i need the global position
Ok - assume you have an edge in group in the current context - the group is selected
model = Sketchup.active_model sel = model.selection group = sel[0] edge = group.entities[0] # Assuming there is only one edge in the group global_start = edge.start.position.transform( group.transformation )
Not that when you open a group or component for editing, the co-ordinates you get in
active_entities
are the global ones. -
@tig said:
If the group is not within the
model.entities
(as ingroup.parent != model
) you need to recursively apply the parent's parent's transformations until it is etc... using awhile parent != model ... end
loop ?As long as the group is within model.active_entities one only need to apply the group's transformation.
And you can't go backwards byparent
as you traverse definitions instead if instances. -
big thanks @ TIG and thomthom. It works
!!
-
Isn't this ("the location of a group") what Ossi01's asking? The example uses
selection
to Id a group, then gets itstransformation
, then itsorigin
based on its location from the model's origin.model = Sketchup.active_model my_selection = model.selection my_selection.each do |ent| if ent.is_a? Sketchup;;Group t=ent.transformation puts t.origin.to_a end end
-
When you get the position of a point [
pt
] in agroup.entities
[or definition's] it is relative to where it was 'made' i.e. for a model it's bounds.min is typically taken as the model.origin. So the point is returned relative to the group's coordinate system not the model's. You can apply thetr=group.transformation
to that pointpt.transform!(tr)
and it is now given in the model's coordinate system... If groups are nested then the transformation of each parent back to the model level has to be taken into consideration... -
@tig said:
tr=group.transformation
to that pointpt.transform!(tr)
Thank you very much for the tip !
Advertisement