# Create the Command object cmd = UI::Command.new("Tenon") { sel = Sketchup.active_model.selection sel.each do |ent| if ent.typename == "Face" vertices = ent.vertices prompts = ["Tenon Depth", "Tenon Offset"] defaults = ["1.0", "0.5"] results = UI.inputbox prompts, defaults, "Tenon Measurements" tenon = find_tenon(ent, results[1]) if tenon != nil tenon.pushpull results[0].to_f end #if end #if end #do } def find_tenon ( face, offs ) offset = offs.to_f tenon_array = Array.new if face.normal == [0,1,0] || face.normal == [0,-1,0] face.vertices.each { |vect| npoint = Geom::Point3d.new 0,0,0 if vect.position.x == get_lower_x(face) npoint.x = offset else npoint.x = -offset end #if if vect.position.z == get_lower_z(face) npoint.z = offset else npoint.z = -offset end #if tform = Geom::Transformation.new npoint xpoint = vect.position.transform tform tenon_array << xpoint } end #if if face.normal == [1,0,0] || face.normal == [-1,0,0] face.vertices.each { |vect| npoint = Geom::Point3d.new 0,0,0 if vect.position.y == get_lower_y(face) npoint.y = offset else npoint.y = -offset end #if if vect.position.z == get_lower_z(face) npoint.z = offset else npoint.z = -offset end #if tform = Geom::Transformation.new npoint xpoint = vect.position.transform tform tenon_array << xpoint } end #if if face.normal == [0,0,1] || face.normal == [0,0,-1] face.vertices.each { |vect| npoint = Geom::Point3d.new 0,0,0 if vect.position.x == get_lower_x(face) npoint.x = offset else npoint.x = -offset end #if if vect.position.y == get_lower_y(face) npoint.y = offset else npoint.y = -offset end #if tform = Geom::Transformation.new npoint xpoint = vect.position.transform tform tenon_array << xpoint } end #if tenon = Sketchup.active_model.active_entities.add_face tenon_array return tenon end #find_tenon def count_number_of_vertices (face) count = 0 face.vertices.each { |v| count += 1 } return count end #count_number_of_vertices def get_lower_x (face) point = face.vertices lowerx = point[0].position.x face.vertices.each { |v| if v.position.x < lowerx lowerx = v.position.x end } return lowerx end #get_lower_x def get_lower_y (face) point = face.vertices lowery = point[0].position.y face.vertices.each { |v| if v.position.y < lowery lowery = v.position.y end } return lowery end #get_lower_y def get_lower_z (face) point = face.vertices upperz = point[0].position.z face.vertices.each { |v| if v.position.z < upperz upperz = v.position.z end } return upperz end #get_lower_z def get_upper_x (face) point = face.vertices upperx = point[0].position.x face.vertices.each { |v| if v.position.x > upperx upperx = v.position.x end } return upperx end #get_upper_x def get_upper_y (face) point = face.vertices uppery = point[0].position.y face.vertices.each { |v| if v.position.y > uppery uppery = v.position.y end } return uppery end #get_upper_y def get_upper_z (face) point = face.vertices uppery = point[0].position.z face.vertices.each { |v| if v.position.z > upperz upperz = v.position.z end } return upperz end #get_upper_z # Validation procedure - check for face cmd.set_validation_proc { sel = Sketchup.active_model.selection ok = sel.find{ |e| e.typename == "Face"} ok ? MF_ENABLED : MF_GRAYED } # Access SketchUp's context menu UI.add_context_menu_handler do |menu| menu.add_separator menu.add_item cmd end