There it is, TBoy:
class BoundsHighlighterTool
def initialize
@ip = Sketchup;;InputPoint.new
@hovered_inst = nil
@global_parent_tra = nil
@global_bb = nil
@labb_global_faces = [] # Faces for the local axes aligned bounding box.
@gabb_global_faces = [] # Faces for the global axes aligned bounding box.
@labb_global_edges = []
@gabb_global_edges = []
@labb_face_color = Sketchup;;Color.new(255,40,0,80)
@gabb_face_color = Sketchup;;Color.new(0,40,255,80)
@labb_edge_color = Sketchup;;Color.new(255,0,0,255)
@gabb_edge_color = Sketchup;;Color.new(0,0,255,255)
@edge_width = 3
end
def deactivate(view)
reset(view)
end
def onMouseMove(flags, x, y, view)
@ip.pick(view, x, y)
ip_path = @ip.instance_path
if ip_path.empty?
reset(view)
return
end
inst = nil
gptra = nil
ip_path.each { |ent|
break if !ent.is_a?(Sketchup;;Group) && !ent.is_a?(Sketchup;;ComponentInstance)
if gptra
gptra = gptra * inst.transformation
elsif inst
gptra = inst.transformation
end
inst = ent
}
unless inst
reset(view)
return
end
return if inst == @hovered_inst
@hovered_inst = inst
@global_parent_tra = gptra
local_bb = @hovered_inst.bounds
# Obtain corners of local axes aligned bounding box in global space
lagc = []
for i in 0..7
lagc << local_bb.corner(i)
end
if @global_parent_tra
lagc.each { |point| point.transform!(@global_parent_tra) }
end
@labb_global_faces = [
[lagc[0], lagc[2], lagc[3], lagc[1]],
[lagc[4], lagc[6], lagc[7], lagc[5]],
[lagc[1], lagc[0], lagc[4], lagc[5]],
[lagc[2], lagc[3], lagc[7], lagc[6]],
[lagc[0], lagc[2], lagc[6], lagc[4]],
[lagc[3], lagc[1], lagc[5], lagc[7]]
]
@labb_global_edges = [
lagc[0], lagc[2],
lagc[2], lagc[6],
lagc[6], lagc[4],
lagc[4], lagc[0],
lagc[3], lagc[1],
lagc[1], lagc[5],
lagc[5], lagc[7],
lagc[7], lagc[3],
lagc[0], lagc[1],
lagc[2], lagc[3],
lagc[4], lagc[5],
lagc[6], lagc[7]
]
# Create global axes aligned bounding box
@global_bb = Geom;;BoundingBox.new()
@global_bb.add(lagc)
# Obtain corners of global axes aligned bounding box in global space
gagc = []
for i in 0..7
gagc << @global_bb.corner(i)
end
@gabb_global_faces = [
[gagc[0], gagc[2], gagc[3], gagc[1]],
[gagc[4], gagc[6], gagc[7], gagc[5]],
[gagc[1], gagc[0], gagc[4], gagc[5]],
[gagc[2], gagc[3], gagc[7], gagc[6]],
[gagc[0], gagc[2], gagc[6], gagc[4]],
[gagc[3], gagc[1], gagc[5], gagc[7]]
]
@gabb_global_edges = [
gagc[0], gagc[2],
gagc[2], gagc[6],
gagc[6], gagc[4],
gagc[4], gagc[0],
gagc[3], gagc[1],
gagc[1], gagc[5],
gagc[5], gagc[7],
gagc[7], gagc[3],
gagc[0], gagc[1],
gagc[2], gagc[3],
gagc[4], gagc[5],
gagc[6], gagc[7]
]
view.invalidate
end
def draw(view)
return unless @hovered_inst
# Draw local axes aligned global bounding box
view.drawing_color = @labb_face_color
@labb_global_faces.each { |face|
view.draw(GL_POLYGON, face)
}
view.drawing_color = @labb_edge_color
view.line_width = @edge_width
view.line_stipple = ''
view.draw(GL_LINES, @labb_global_edges)
# Draw global axes aligned global bounding box
view.drawing_color = @gabb_face_color
@gabb_global_faces.each { |face|
view.draw(GL_POLYGON, face)
}
view.drawing_color = @gabb_edge_color
view.line_width = @edge_width
view.line_stipple = ''
view.draw(GL_LINES, @gabb_global_edges)
end
def reset(view)
return false unless @hovered_inst
@hovered_inst = nil
@global_parent_tra = nil
@global_bb = nil
@labb_global_faces.clear
@gabb_global_faces.clear
@labb_global_edges.clear
@gabb_global_edges.clear
view.invalidate
return true
end
end # class BoundsHighlighterTool
Sketchup.active_model.select_tool(BoundsHighlighterTool.new)
This time we iterate through the InputPoint's instance_path and transform the bounding box of the deepest instance across all the the parent groups/component instances in the path.