Below is a code example for verifying if a selected edge is either 'Concave' or 'Convex'.
How to use:
Create .rb file (name it 'concave-convex.rb' for example) and copy & paste the code below. Then place the file in the SketchUp Plugins folder.
Activate the tool inside Sketchup by going to Plugins or Extension Menu
-> Selected Edge Concave or Convex?
Done! If you selected a single SketchUp edge that was used by two edges a message will be prompted saying if the edge is concave or convex.
Also, remember to re-name the modules to make them unique so that your ruby script plays nice with other scripts in the Plugins folder.
module DevName
module ToolName
class Main
def activate
model = Sketchup.active_model
selection = model.selection
edges = selection.grep(Sketchup::Edge)
first_edge = edges[0]
if first_edge.nil?
line1 = "Select a 'single edge' used by two faces\n"
line2 = 'to determine if the edges is concave or convex.'
msg = line1 + line2
UI.messagebox(msg, MB_OK)
Sketchup.active_model.select_tool(nil)
return
end
msg = if concave?(first_edge)
'Selected Edge is concave'
else
'Selected Edge is convex'
end
UI.messagebox(msg, MB_OK)
Sketchup.active_model.select_tool(nil)
end
# Return true if edge is concave and returns false if convex
def concave?(edge)
faces = edge.faces
if faces.length != 2
line1 = "Select a 'single edge' used by two faces\n"
line2 = 'to determine if the edges is concave or convex.'
msg = line1 + line2
UI.messagebox(msg, MB_OK)
Sketchup.active_model.select_tool(nil)
return
end
fn1 = faces.first.normal
fn2 = faces.last.normal
if !fn1.parallel?(fn2)
vector = fn1 * fn2
vector.samedirection?(edge.line[1]) == edge.reversed_in?(faces[0])
end
end
# # #
end
unless defined?(@loaded)
UI.menu('Plugins').add_item('Selected Edge Concave or Convex?') do
Sketchup.active_model.select_tool(DevName::ToolName::Main.new)
end
@loaded = true
end
end
end