@anton_s said:
Here's what I've got.
def self.currentPos(parent, child_pos) #Get the position of the point relative to parent's transformation
> return child_pos unless (parent.class == Sketchup;;Group) and (parent.class == Sketchup;;ComponentInstance)
> tra = parent.transformation.origin.to_a
> xaxis = parent.transformation.xaxis.to_a
> yaxis = parent.transformation.yaxis.to_a
> zaxis = parent.transformation.zaxis.to_a
> # my experimented formule
> external_pos[x] = tra[0] + child_pos[0]*xaxis[0] + child_pos[1]*yaxis[0] + child_pos[2]*zaxis[0]
> external_pos[y] = tra[1] + child_pos[0]*xaxis[1] + child_pos[1]*yaxis[1] + child_pos[2]*zaxis[1]
> external_pos[z] = tra[2] + child_pos[0]*xaxis[2] + child_pos[1]*yaxis[2] + child_pos[2]*zaxis[2]
> #external_pos = child_pos.transform(parent.transformation).to_a #alternative sketchup formula
> return external_pos
> end
Copy to editor to unwrap the code lines.
It basically shows how that transform
formula works
By the way If you have sketchy physics, you can see play with something similiar here: Navigation System
Thanks for your code. But I still did not get the coordinate that I want, the return coordinate is equal to the child's coordinate. The type of the child is Sketchup::Face, and the type of its parent is Sketchup::ComponentDefinition. I made a group like this:
model = Sketchup.active_model;
groups = [];
model.definitions.each{|d| groups << d if d.group? }
entities = model.entities;
selection = model.selection;
pgrp = [];
groups.each{|d| pgrp << d.instances[0] if d.instances[0].name=="car_top" }
tmpents = pgrp[0].entities;
#print pgrp[0]
faces = tmpents.find_all{|entity|entity.class==Sketchup;;Face}
ctr = faces[8].bounds.center
print ctr
pos = self.currentPos(pgrp[0], ctr)
print pos
pgrp[0] is a group that contain faces[8]. May be there are some bugs...