Thanks. Looks like you made total_repair_broken_lines a global. That makes more sense than to create a useless stack as I did. I didn't want to create a stack either but I didn't want to create a global, and I am not 100% familiar with Ruby/am a bit forgetful. I did some searching now though and I see that @@ is class scope, so how about @@ instead of $?
If the code stays here people won't be able to find it very easily. How about re-releasing this plugin, as well as that "default face" snippet you made earlier for me, in the plugins forum?
Also: another problem I noticed is that it tries to repair lines that aren't repairable, like curve endings and single lines. (attached)
### Original idea (c) Carlo Roosen 2004
### Modified (c) TIG 2011
### Now also repairs edges inside groups/instances in selection...
###
require 'sketchup.rb'
###
class Repair_broken_lines
def initialize(ents=nil)
model=Sketchup.active_model
lines_to_go=[]
if not ents
@@total_repair_broken_lines=0
ss=model.selection.to_a
begin
model.start_operation("Repair Broken Lines",true)
rescue
model.start_operation("Repair Broken Lines")
end
else
ss=ents
end#if
#check all edges in selection set OR entities passed as argument
ss.each{ |e|
if e.kind_of?(Sketchup;;Edge) #take both vertices
e.vertices.each{ |v| #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
#make a new line from that vertex to a random point
pt=Geom;;Point3d.new(1+rand, 1+rand, 1+rand)
nline=e.parent.entities.add_line(v.position, pt)
lines_to_go << nline if nline and nline.valid?
end#if
end#if
}#end v
elsif e.kind_of?(Sketchup;;Group)
Repair_broken_lines.new(e.entities.to_a)
elsif e.kind_of?(Sketchup;;ComponentInstance)
Repair_broken_lines.new(e.definition.entities.to_a)
end#if
}#end e
if not @@total_repair_broken_lines
@@total_repair_broken_lines=lines_to_go.length
else
@@total_repair_broken_lines=@@total_repair_broken_lines + lines_to_go.length
end#if
lines_to_go.each{ |e| e.erase! if e.valid? }#erase all lines_to_go
if not ents
model.commit_operation
UI.messagebox("#{@@total_repair_broken_lines} Lines Repaired.")
end#if
end#def initialize
end#class
###
if not file_loaded?(File.basename(__FILE__))
if $submenu4 # TIG menus
$submenu4.add_item("Repair Broken Lines [Selection]"){ Repair_broken_lines.new() }
else
UI.menu("Plugins").add_item("Repair Broken Lines [Selection]"){ Repair_broken_lines.new() }
end
end
file_loaded(File.basename(__FILE__))
###
circle.skp