Skip to content

Instantly share code, notes, and snippets.

@noelwarr
Created May 14, 2013 10:42
Show Gist options
  • Save noelwarr/5575091 to your computer and use it in GitHub Desktop.
Save noelwarr/5575091 to your computer and use it in GitHub Desktop.
Stitch cavities in meshes in SketchUp
class DynameshTool
def initialize
end
def sort_vertices(v1,v2,orientation,direction,view)
coords = [v1,v2].collect{|v|
pos = view.screen_coords(v.position)
case orientation
when :horizontal then pos[0]
when :vertical then pos[1]
end
}
if (coords[0] > coords[1])
v1, v2 = v2, v1
end
if direction == :more
return v2, v1
else
return v1, v2
end
end
def onKeyUp(key, repeat, flags, view)
selection = Sketchup.active_model.selection
edge = selection[0]
case key
when VK_LEFT then orientation, direction = :horizontal, :less
when VK_RIGHT then orientation, direction = :horizontal, :more
when VK_DOWN then orientation, direction = :vertical, :more
when VK_UP then orientation, direction = :vertical, :less
end
v1, v3 = sort_vertices( edge.start,
edge.end,
orientation,
direction,
view)
next_edge = v1.edges.find{|e|
e != edge && e.faces.length == 1
}
v2 = next_edge.other_vertex(v1)
face = Sketchup.active_model.entities.add_face([v1,v2,v3].collect{|v|v.position})
new_edge = (face.edges - [edge,next_edge]).first
selection.clear
selection.add new_edge
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment