A problem with that script is that it does not seem to always dig inside groups/components correctly and misses some lines.
Edit: tried this.... doesn't work. I have a feeling I am missing something.
Edit 2: Used "if (e.class != Sketchup::Face)" instead of
"if (e.class == Sketchup::Group)"... why does one work and not the other? (the == group one doesn't seem to hit?) Also... any better solutions here? This is the best I could cobble up..
require 'sketchup.rb'
# (c) Carlo Roosen 2004
def repair_broken_lines (eparent)
total = 0
trunk = Array.new
ss = eparent.entities
#search all edges in selection set
for e in ss
if (e.kind_of?(Sketchup;;Edge))
p=e.parent
#take both vertices
for v in e.vertices
#take all edges connected to v (including e)
es=v.edges
#when two edges are connected
if (es.length==2)
vec1 = es[0].line[1]
vec2 = es[1].line[1]
#and both are in the same direction
if (vec1.parallel?(vec2))
#then the two lines can be repaired
#this is done by generating a new line from the vertex to a random point
l = p.entities.add_line (v.position, Geom;;Point3d.new(3.45,6.78,9.12))
#and put that line in a trunk
trunk.push(l)
end
end
end
else
if (e.class != Sketchup;;Face)
total += repair_broken_lines (e)
end
end
end
#erase all lines in trunk
total += trunk.length
for l in trunk
l.erase!
end
return total
end
def repair_broken_lines_recurse
total = 0;
m = Sketchup.active_model;
# Define everything as one undo operation.
m.start_operation "Repair Broken Lines"
total = repair_broken_lines (m)
UI.messagebox ("#{total} lines repaired")
m.commit_operation
end
selection=Sketchup.active_model.selection
if( not file_loaded?("repair_broken_lines.rb") )
UI.add_context_menu_handler do |context_menu|
if selection.count>1
context_menu.add_item("Repair Broken Lines") { repair_broken_lines_recurse }
end
end
end
UI.menu("Plugins").add_item("Repair Broken Lines") { repair_broken_lines_recurse }
file_loaded ("repair_broken_lines.rb")