The API implies that Components can only be glued to faces.
However, a component instance that is not in a group can be glued to a face inside that group.
(Also a component instance can be glued to a face inside a different component instance.)
So the method: componentInstance.glued_to can return either a face, a group, or another component.
What’s the easiest way to find the actual face inside the group (or other instance) that the instance is actually glued to?
Actually all I need is the face normal, so I could create a vertical vector, use it to create a vertical cline, transform the cline using the instance transform, then find the resulting cline direction. I think I answered my own question.
Not sure what you really want, but an illustration might help:
inst.transformation.zaxis
Great. That’s much better. I knew that method but didn’t connect the dots.
But I also need the plane of the face. I don’t see a straightforward way to get that.
Do you?
Geom
module said:
A plane can be represented as either an Array
of a point and a vector, or as an Array
of 4 numbers that give the coefficients of a plane equation.
normal = inst.transformation.zaxis
point = inst.transformation.origin
plane = [ point, normal ]
I’m not sure if I understand the question, but the “Face” class includes methods for “normal” and “plane”. Instead of “[point, normal]”, the plane value is the OTHER kind (an array with four values). The return values will be relative to the local coordinate system.
Dan’s answer is what I need. (I must have had some stupid pills this morning.)
Bruce: I cannot access the face methods because componentInstance.glued_to doesn’t return a face if the face is inside a group.and the instance is not in that group.
… of course my example makes bug assumptins, that the instance’s origin will be ON the face’s plane.
Try using a pickhelper (untested).
# Get the glued_to face's plane
view = Sketchup::active_model.view
inpt = inst.transformation.origin
x, y = view.screen_coords(inpt)
ph = view.pick_helper
ph.do_pick(x, y)
ents = ph.all_picked
target = inst.glued_to
if target.is_a?(Sketchup::Group)
ents.delete_if{|e| e.parent != target }
else
ents.delete_if{|e| e.parent != target.definition }
end
# now ents should just have what is glued_to
face = ents.find{|e|
e.is_a?(Sketchup::Face) &&
e.classify_point(inpt) != Sketchup::Face::PointUnknown &&
e.classify_point(inpt) != Sketchup::Face::PointNotOnPlane
}
if face # nil if not found
# use the face
plane = face.plane
end