=begin
#-----------------------------------------------------------------------------
 Dxf_In_v1.14
(c) honoluludesktop 2010

Freely use, and abuse at your own risk. Fitness of use is 
not warranty implied.

Place this file into the "Google SketchUp 8\Plugins" Folder. To use, 
select File, Input Dxf, and point to a Dxf file.  For help, select a file 
to open, and at the options menu, select "Help Options: Get Help"

Dxf_In will attempt to process erroneously, manually edited files as 
long as the group code is in the correct sequence, including files
that Sketchup's import rejects.

09/24/2010 - v 0.38 Alpha, first release 
09/26/2010 - v 0.40 Alpha, fixed arcs, and added error messages.
09/27/2010 - v 0.42 Alpha, fixed arcs, and speed improved.
09/29/2010 - v 0.45 Alpha, blocks, error messages.
09/30/2010 - v 0.50 Beta, added lwpolylines, fixed blocks.
10/03/2010 - v 1.0   Polyline mesh, error messages, minor fixes.
10/10/2010 - v 1.2   Select import scale, and origin.
10/12/2010 - v 1.5   Add face layer, materials, and option menu
10/14/2010 - v 1.6   Corrected metric conversion table
10/15/2010 - v 1.9	 Pointer by component bound corner, colors by
                                 Sketchup color names, or Acad color number.
10/19/2010 - v 1.10 Scaled transformed entities on the pointer.
10/21/2010 - v 1.14 Interface improvements, and save user options.
#-----------------------------------------------------------------------------
=end
require 'sketchup.rb'
def atelier_main_proc
	model = Sketchup.active_model
	entities = model.active_entities
	definitions = model.definitions
	load_acad_colors								#put acad colors into memory
	materials = model.materials				#put current model colors into memory
	@color1=[]
	materials.each do |e|
		@color1.push e
	end
	ext_name = ""
	while ext_name != "DXF" and ext_name != "OLD"#.OLD is for pp 4d models
		chosen_file = UI.openpanel "Select DXF File","", "*.Dxf"
		name_parts = chosen_file.split('.')
		ext_name = name_parts[1].upcase
		name_parts = chosen_file.split('\\')						#split Drive\FilePath\Name.Ext into parts
		n_count = -1
		name_parts.each do |n| 										#count parts
			n_count=n_count+1
		end
		my_file_name = name_parts[n_count]					#get file name
	end
	@model_origin=true
	@t = Geom::Transformation.scaling 1
	options_flag=0
	a_values=[]
	s_value=""
	s_value = Sketchup.read_default "honoluludesktop", "values", "None:Inches:Model:to Faces:by Number"
	a_values = s_value.split(":")
	units_list=["Meters","Centimeters","Millimeters","Inches","Feet"].join("|")
	model_selection=["Model","Pointer"].join("|")
	convert_selection =["to Faces","to Edges"].join("|")
	import_texture =["by Names","by Number","by Model","None"].join("|")
	update_this =["None","Get Update","Get Help","Save Options"].join("|")
	prompts=["Help options: ","Import unit: ","Select origin: ","Polylines: ","Materials: "]
	enums=[update_this,units_list, model_selection,convert_selection,import_texture]
	results = inputbox prompts, a_values, enums, my_file_name+" Options"
	return if not results
	case results[0]
	when "Get Update"
		url = "http://forums.sketchucation.com/viewtopic.php?f=323&t=31186&start=0#p274199"
		UI.openURL("#{url}#")
		return
	when "None"
		#do nothing
	when "Get Help"
		UI.messagebox help, MB_OK |80
	when "Save Options"
		options_flag=1
	end
	case results[1]
	when "Meters"
		scale_conv=39.3700787 
		scale_sel="Meters"
	when "Centimeters"
		scale_conv=0.393700787 
		scale_sel="Centimeters"
	when "Millimeters"
		scale_conv=0.0393700787 
		scale_sel="Millimeters"
	when "Feet"
		scale_conv=12
		scale_sel="Feet"
	when "Inches"
		scale_conv=1
		scale_sel="Inches"
	end
	@t = Geom::Transformation.scaling scale_conv 	
	case results[2]
	when "Model"
		@model_origin=true
		origin_sel="Model"
	when "Pointer"
		@model_origin=false
		origin_sel="Pointer"
	end
	case results[3]
	when "to Faces"
		@dface_option = 1
		dface_sel="to Faces"
	when "to Edges"
		@dface_option = 0
		dface_sel="to Edges"
	end
	case results[4]
	when "by Names"
		@material_option = 1
		material_sel="by Names"
	when "by Number"
		@material_option = 2
		material_sel="by Number"
	when "by Model"
		@material_option = 3
		material_sel="by Model"
	when "None"
		@material_option = 0
		material_sel="None"
	end
	if options_flag == 1
		a_values = ["None",scale_sel,origin_sel,dface_sel,material_sel]
		s_value = a_values.join(":")
		result = Sketchup.write_default "honoluludesktop","values", s_value
	end
	@count = 0
	@next_off = -1
	@entities_flag = 0
	@block_flag = 0
	@block_ttl = 0
	@polyline_flag = 0
	@lwpolyline_flag = 0
	@polyline_ttl = 0
	@line_flag = 0
	@line_ttl = 0
	@circle_flag = 0
	@circle_ttl = 0
	@arc_flag = 0
	@arc_ttl = 0
	@extrusion_normal = 0
	@dface_flag = 0
	@dface_ttl = 0
	@vertex_flag = 0
	@last_vertex_pt = []
	@last_line = ""
	@vertex_coord = []
	@vertex_pt = []
	@entity = []
	@group_all = []
	@set_polyface = 0
	@insert_names = []
	insert_flag = 0
	@block_layer						
	@block_name
	@block_x = 0.0
	@block_y = 0.0
	@block_z = 0.0
	vector = Geom::Vector3d.new 0,0,1  
	@vector2 = Geom::Vector3d.new 1,0,0  
	@vector3 = vector.normalize!
	@cancel_unsupported_error_flag = 1
	@cancel_face_error_flag = 1
	@cancel_polyline_error_flag = 1
	@cancel_nested_blk_error = 1
	@entity_layer
	@entity_material
	@set_material = 0
	blk_flag = 0
	count = 0
	this_line = ""
	last_line = ""
	odd_number = 1
	insert_ttl = 0
	count_100 = 0
	count_bar = ""
	ttl_count = 1
	ramFile = []
	@su_colors = []
	@su_colors = Sketchup::Color.names
	aFile = File.open(chosen_file, "r")
	aFile.each_line do |line|						
		count = count +1
		if count == odd_number				
			odd_number = odd_number + 2
			line = line.strip
		end
		last_line = this_line					
		this_line = line
		count_100 = count_100 +1			
		if count_100 == 100
			count_bar = count_bar + "|"
			if count_bar.length == 150
				ttl_count = ttl_count+1
				count_bar = ""
			end
			count_100 = 0
			Sketchup.set_status_text "Stage 1 [  #{ttl_count}  ]: #{count_bar}", SB_PROMPT
		end
		if line == "BLOCK\n" 							
			blk_flag = 1
			else if line == "ENDBLK\n"
				blk_flag = 0
				else if line == "INSERT\n" and last_line == "0" and blk_flag == 1
					if @cancel_nested_blk_error == 1		
						result = UI.messagebox "Nested blocks not supported", MB_OKCANCEL
						if result == 2
							@cancel_nested_blk_error = 0		
						end
					end
					else if line == "INSERT\n" and last_line == "0" and blk_flag == 0
						insert_flag = 1
						else if(last_line == "8" or last_line == "2" or last_line == "10" or last_line == "20" or last_line == "30") and insert_flag == 1
							if last_line == "30"
								insert_flag = 0
							end				
							insert_ttl = insert_ttl + 1
							@insert_names.push line
						end
					end
				end
			end
		end
		ramFile.push line													#save dxf file as ram file
	end
	aFile.close
	count = 0
	last_line = ""
	this_line = ""
	@odd_number = 1
	@polyface_flag = 0
	@polyface_cnt_flag = 0
	@lwpline_verticies = 0
	@unsupported_entities = 0
	@bad_faces = 0
	count_100 = 0
	count_bar = ""
	cnt_count = 1
	@master_group = entities.add_group
	@block_group = @master_group.entities.add_group
	ramFile.each do |@line|				
		@count = @count + 1					
		@last_line = this_line						
		this_line = @line							
		count_100 = count_100 +1			
		if count_100 == 100
			count_bar = count_bar + "|"
			if count_bar.length == 150
				cnt_count = cnt_count+1
				count_bar = ""
			end
			count_100 = 0
			Sketchup.set_status_text "Stage 2 [ #{cnt_count}/#{ttl_count} ]: #{count_bar}", SB_PROMPT
		end
		if @line == "BLOCK\n" 													
			@block_flag = 1															
			@block_group = @master_group.entities.add_group
			else if @line == "ENDBLK\n" 							
				@block_flag = 0													
				@block_group.name = @block_name						
				if @block_layer != "0" and @block_layer != nil		
					new_layer = Sketchup.active_model.layers.add @block_layer.to_s
					@block_group.layer = new_layer
				end
				else if @line == "ENTITIES\n"						
					@entities_flag = 1
					else if @line == "ENDSEC\n" and @entities_flag == 1
						@entities_flag = 0											
						else if @last_line == "70" and @line.to_f == 64 
							@polyface_flag = 1
							else if @block_flag == 1
								block_in														
								else if @block_flag == 0 and @entities_flag == 1
									entities_in											
								end
							end
						end
					end
				end
			end
		end
	end																							
	if @polyline_ttl+@line_ttl+@dface_ttl+@arc_ttl+@circle_ttl == 0
		UI.messagebox "<Error> or Empty File"		
		return
	end	
	if @model_origin == false									
		my_instance = @master_group.to_component
		my_definition = my_instance.definition
		my_definition.entities.transform_entities(@t,my_definition.entities.to_a)
		bb=my_instance.bounds									
	 	my_definition.name = my_file_name				
		my_definition.insertion_point = bb.corner(0)	
		select = UI.messagebox ("Blocks | Groups         :  "+ @block_ttl.to_s+"\n\nUnsupported Entities:  "+@unsupported_entities.to_s+"\nBad Faces                 :  "+@bad_faces.to_s+"\n\nConnected Edges     :  "+@polyline_ttl.to_s+"\nFaces                        :  "+@dface_ttl = @dface_ttl.to_s+"\nLines                         :  "+@line_ttl.to_s+"\nArcs                          :  "+@arc_ttl.to_s+"\nCircles                       :  "+@circle_ttl.to_s+ "\n\nLocate Dxf Entities", MB_OK  |80)
		my_instance.erase!							
		model.place_component my_definition		
	else
		@master_group.transform! @t							
		select = UI.messagebox ("Blocks | Groups         :  "+ @block_ttl.to_s+"\n\nUnsupported Entities:  "+@unsupported_entities.to_s+"\nBad Faces                 :  "+@bad_faces.to_s+"\n\nConnected Edges     :  "+@polyline_ttl.to_s+"\nFaces                        :  "+@dface_ttl = @dface_ttl.to_s+"\nLines                         :  "+@line_ttl.to_s+"\nArcs                          :  "+@arc_ttl.to_s+"\nCircles                       :  "+@circle_ttl.to_s+ "\n\nGroup Dxf Entities", MB_YESNO  |80)
		if select == 7 													
			@master_group.explode
		else 															
			if @master_group.name == ""						
				@master_group.name = my_file_name
			end
		end
	end
end

def block_in														
	if @last_line == "2"
		insert_names_line = -1
		@block_name = ""
		@block_x = 0.0
		@block_y = 0.0
		@block_z = 0.0
		@insert_names.each do |insert_vari|			
			insert_names_line = insert_names_line + 1
			if insert_vari == @line
				@block_ttl = @block_ttl + 1
				@block_layer = @insert_names[insert_names_line-1].strip
				@block_name = @insert_names[insert_names_line].strip
				@block_x = @insert_names[insert_names_line+1].to_f
				@block_y = @insert_names[insert_names_line+2].to_f
				@block_z = @insert_names[insert_names_line+3].to_f
				if  @polyface_flag == 1 and @block_name != "AME_NIL"
					@polyface_flag = 0
					if @cancel_unsupported_error_flag == 1
						@unsupported_entities = @unsupported_entities +1
						result = UI.messagebox "Block "+@block_name+" contains a unsupported mesh     ", MB_OKCANCEL
						if result == 2
							@cancel_unsupported_error_flag = 0
						end
					end
				end
				@polyface_flag = 0				
			end
		end
	end
	if @block_name != ""
		entities_in
	end
end

def circle_in
	if @last_line == "10" or @last_line == "20" or @last_line == "30" or @last_line == "40"
		@entity.push @line.to_f
		if @last_line == "40"
			@circle_ttl = @circle_ttl + 1
			@circle_flag = 0
			if @block_flag == 1			
				group = @block_group.entities.add_circle [@entity[0]+@block_x, @entity[1]+@block_y, @entity[2]+@block_z], @vector3, @entity[3]
			else											
				group = @master_group.entities.add_circle [@entity[0]+@block_x, @entity[1]+@block_y, @entity[2]+@block_z], @vector3, @entity[3]
			end
			@entity.clear
		end
	end
end

def arc_in
	if @last_line == "230"					
		if @line == "-1.0\n"
			@extrusion_normal = 1
		else 
			@extrusion_normal = 0
		end
		else if @last_line == "10" or @last_line == "20" or @last_line == "30" or @last_line == "40" or @last_line == "50" or @last_line == "51" 
			@entity.push @line.to_f
			if @last_line == "51"
				@arc_ttl = @arc_ttl + 1
				@arc_flag = 0
				if @block_flag == 1				
					if @entity[5] == 0.0 or @entity[5] < @entity[4]
						@entity[5] = @entity[5]+360.0
					end			
					if @extrusion_normal != 1	
						group = @block_group.entities.add_arc [@entity[0]+@block_x, @entity[1]+@block_y, @entity[2]+@block_z],@vector2,@vector3,@entity[3],(@entity[4]*Math::PI)/180,((@entity[5])*Math::PI)/180
					else									
						group = @block_group.entities.add_arc [(1.5*-@entity[0])+@block_x, -@entity[1]+@block_y,-@entity[2]+@block_z],@vector2,@vector3,@entity[3],((90+@entity[4])*Math::PI)/180,((90+@entity[5])*Math::PI)/180
					end
				else									
					if @entity[5] == 0.0 or @entity[5] < @entity[4]
						@entity[5] = @entity[5]+360.0
					end			
					if @extrusion_normal != 1	
						group = @master_group.entities.add_arc [@entity[0]+@block_x, @entity[1]+@block_y, @entity[2]+@block_z],@vector2,@vector3,@entity[3],(@entity[4]*Math::PI)/180,((@entity[5])*Math::PI)/180
					else									
						group = @master_group.entities.add_arc [(1.5*-@entity[0])+@block_x, -@entity[1]+@block_y,-@entity[2]+@block_z],@vector2,@vector3,@entity[3],((90+@entity[4])*Math::PI)/180,((90+@entity[5])*Math::PI)/180
					end
				end
				@entity.clear
			end
		end
	end
end

def dface_in
	get_layer_material
	else if @last_line == "10" or @last_line == "20" or @last_line == "30" or @last_line == "11" or @last_line == "21" or @last_line == "31" or @last_line == "12" or @last_line == "22" or @last_line == "32" or @last_line == "13" or @last_line == "23" or @last_line == "33"
		@entity.push @line.to_f
		if @last_line == "33"
			@dface_ttl = @dface_ttl + 1
			@dface_flag = 0
			if @block_flag == 1					
				begin
					ent_group = @block_group.entities.add_face([@entity[0]+@block_x,@entity[1]+@block_y,@entity[2]+@block_z],[@entity[3]+@block_x,@entity[4]+@block_y,@entity[5]+@block_z],[@entity[6]+@block_x,@entity[7]+@block_y, @entity[8]+@block_z],[@entity[9]+@block_x,@entity[10]+@block_y,@entity[11]+@block_z])
					put_layer_material(ent_group)			
				rescue
					type = "Block name "+@block_name+" bad 3dFace  "
					database_error(type)
				end
			else								
				begin
					ent_group = @master_group.entities.add_face([@entity[0]+@block_x,@entity[1]+@block_y,@entity[2]+@block_z],[@entity[3]+@block_x,@entity[4]+@block_y,@entity[5]+@block_z],[@entity[6]+@block_x,@entity[7]+@block_y, @entity[8]+@block_z],[@entity[9]+@block_x,@entity[10]+@block_y,@entity[11]+@block_z])
					put_layer_material(ent_group)	
				rescue
					type = " Bad 3dFace  "
					database_error(type)
				end
			end
			@entity.clear
		end
	end
end

def polyline_in
	get_layer_material
	if @line == "VERTEX\n" and @last_line == "0"
		@vertex_flag = 1
		else if(@last_line == "10" or @last_line == "20" or @last_line == "30") and @vertex_flag == 1
			@vertex_pt.push @line.to_f
			if @last_line == "30" and @last_vertex_pt != [@vertex_pt[0],@vertex_pt[1],@vertex_pt[2]] and @vertex_flag == 1
				if [@vertex_pt[0],@vertex_pt[1],@vertex_pt[2]] == [0.0,0.0,0.0] and @polyface_flag == 1
					if @set_polyface == 0
						result = UI.messagebox "Unsupported PolyFace Mesh",MB_OKCANCEL
						if result == 2
							@set_polyface = 1
						end
					end
				else									
					@last_vertex_pt = [@vertex_pt[0],@vertex_pt[1],@vertex_pt[2]]
					@vertex_coord.push [@vertex_pt[0] + @block_x, @vertex_pt[1] + @block_y, @vertex_pt[2] + @block_z]
				end
				@vertex_pt.clear
				@vertex_flag = 0
			end	
			else if @line == "SEQEND\n"	
				@polyline_flag = 0
				@last_vertex_pt.clear
				if	@dface_option == 0 and not @vertex_coord.empty? 
					@polyline_ttl = @polyline_ttl + 1
					if @block_flag == 1		
						group = @block_group.entities.add_edges @vertex_coord
					else									
						group = @master_group.entities.add_edges @vertex_coord
					end
					else if @dface_option == 1 and not @vertex_coord.empty?	
						@dface_ttl = @dface_ttl + 1
						if @block_flag == 1	
							begin						
								this_face = @block_group.entities.add_face @vertex_coord	
								put_layer_material(this_face)
							rescue
								type = "Block name "+@block_name+" bad polyline  "
								database_error(type)
							end
						else								
							begin
								group = @master_group.entities.add_face @vertex_coord
								put_layer_material(group)
								rescue
								@dface_ttl = @dface_ttl - 1
								if @cancel_polyline_error_flag == 1
									selection = UI.messagebox "<Error> bad polyline", MB_OKCANCEL
									if selection == 2
										@cancel_polyline_error_flag = 0
									end
								end
							end
						end
					end
				end
				@vertex_coord.clear
			end
		end
	end
end

def lwpolyline_in
	if @last_line == "90"
		@lwpline_verticies = @line.to_f
		else if @last_line == "10" or @last_line == "20"
			@vertex_pt.push @line.to_f
			if @last_line == "20" 
				@lwpline_verticies = @lwpline_verticies - 1
				@vertex_coord.push [@vertex_pt[0] + @block_x, @vertex_pt[1] + @block_y, 0.0 + @block_z]
				@vertex_pt.clear
			end
			else if 	@lwpline_verticies == 0 or @line == "0"	#end of lwpolyline
				if not @vertex_coord.empty?
					@polyline_ttl = @polyline_ttl + 1
					@lwpolyline_flag = 0
					@lwpline_verticies = 0
					if @block_flag == 1			#add entity to @block_group.@master_group
						group = @block_group.entities.add_edges @vertex_coord
					else										#add entity to @master_group
						group = @master_group.entities.add_edges @vertex_coord
					end
				end
				@vertex_coord.clear
			end
		end
	end
end

def line_in
	if @last_line == "10" or @last_line == "20" or @last_line == "30" or @last_line == "11" or @last_line == "21" or @last_line == "31"
		@entity.push @line.to_f				
		if @last_line == "31"						
			@line_ttl = @line_ttl + 1		
			@line_flag = 0							
			if @block_flag == 1				
				group = @block_group.entities.add_line [@entity[0]+@block_x, @entity[1]+@block_y, @entity[2]+@block_z], [@entity[3]+@block_x,@entity[4]+@block_y, @entity[5]+@block_z]
			else											
				group = @master_group.entities.add_line [@entity[0]+@block_x, @entity[1]+@block_y, @entity[2]+@block_z], [@entity[3]+@block_x,@entity[4]+@block_y, @entity[5]+@block_z]
			end
			@entity.clear
		end
	end
end

def entities_in								
	if @line == "LINE\n" and @last_line == "0"	
		@line_flag = 1							
		else if @line_flag == 1
			line_in
			else if @line == "LWPOLYLINE\n" and @last_line == "0"
				@lwpolyline_flag = 1
				else if @lwpolyline_flag == 1
					lwpolyline_in
					else if @line == "POLYLINE\n" and @last_line == "0"
						@polyline_flag = 1
						else if @polyline_flag == 1
							polyline_in
							else if @line == "3DFACE\n" and @last_line == "0"
								@dface_flag = 1
								else if @dface_flag == 1
									dface_in
									else if @line == "CIRCLE\n" and @last_line == "0"
										@circle_flag = 1
										else if @circle_flag == 1
											circle_in
											else if @line == "ARC\n" and @last_line == "0"
												@arc_flag = 1
												else if @arc_flag == 1
													arc_in
												end
											end
										end
									end
								end
							end
						end
					end
				end
			end
		end
	end
end

def get_layer_material
	if @last_line == "8"
		@entity_layer = @line.strip
		model = Sketchup.active_model  
		layers = model.layers 
		layer_flag = false
		layers.each do |layer|
			if @entity_layer == layer
				layer_flag = true
			end
		end
		if layer_flag == false
			layers.add @entity_layer.to_s
		end
		else if @last_line == "62"				
			@entity_material = @line.strip	
			if @material_option == 2		
				@set_material = 1					
			end
		end
	end
end

def put_layer_material(ent_group)
	ent_group.layer = @entity_layer			
	if @material_option == 0 					
		#do nothing
		else if @material_option == 1 	
			@su_colors.each do |ea_color|
				if ea_color == @entity_material
					color = Sketchup::Color.new @entity_material
					ent_group.material = color
				end
			end
			else if @material_option == 2  and @entity_material.to_i < 256  and @set_material == 1 
				@acad_colors.each do |eacolor|
					if eacolor[0] == @entity_material.to_i	
						color = Sketchup::Color.new [eacolor[1],eacolor[2],eacolor[3]] 
						ent_group.material = color
					end
				end
				@set_material = 0						
				else if @material_option == 3 	
					@color1.each do |mcolor|
						if mcolor.display_name == @entity_material
							color = Sketchup::Color.new (mcolor.color)
							ent_group.material = color
						end
					end
				end
			end
		end
	end
end

def database_error(type)
	@dface_ttl = @dface_ttl - 1
	@bad_faces = @bad_faces + 1
	if @cancel_face_error_flag == 1
		selection = UI.messagebox "<Error>"+type, MB_OKCANCEL
		if selection == 2
			@cancel_face_error_flag = 0
		end
	end
end

def load_acad_colors
	@acad_colors = [[0,0,0,0],[1,255,0,0],[2,255,255,0],[3,0,255,0],[4,0,255,255],[5,0,0,255],[6,255,0,255],[7,255,255,255],
	[8,65,65,65],[9,128,128,128],[10,255,0,0],[11,255,170,170],[12,189,0,0],[13,189,126,126],[14,129,0,0],[15,129,86,86],
	[16,104,0,0],[17,104,69,69],[18,79,0,0],[19,79,53,53],[20,255,63,0],[21,255,199,170],[22,189,46,0],[23,189,131,126],
	[24,129,31,0],[25,129,96,86],[25,104,25,0],[27,104,78,69],[28,79,19,0],[29,79,59,53],[30,255,127,0],[31,255,212,170],
	[32,189,94,0],[33,189,157,126],[32,189,94,0],[33,189,157,126],[34,129,64,0],[35,129,107,86],[36,104,52,0],[37,104,86,69],
	[38,79,39,0],[38,79,39,0],[39,79,66,53],[40,255,191,0],[41,255,234,170],[42,189,141,0],[43,189,173,126],[44,129,96,0],
	[45,129,118,86],[46,104,78,0],[47,104,95,69],[48,79,59,0],[49,79,73,53],[50,255,255,0],[51,255,255,170],[52,189,189,0],
	[53,189,189,126],[54,129,129,86],[55,129,129,86],[56,104,104,0],[57,104,104,69],[58,79,79,0],[59,79,79,53],[60,191,255,0],
	[61,234,255,170],[62,141,189,0],[63,173,189,126],[64,96,129,0],[65,118,129,86],[66,78,104,0],[67,95,104,69],[68,59,79,0],
	[69,73,79,53],[70,127,255,0],[71,212,255,170],[72,94,189,0],[73,157,189,126],[74,64,129,0],[75,107,129,86],[76,52,104,0],
	[77,86,104,69],[78,39,79,0],[79,66,79,53],[80,63,255,0],[81,191,255,170],[82,46,189,0],[83,141,189,126],[84,31,129,0],
	[85,96,129,86],[86,25,104,0],[87,78,104,69],[88,19,79,0],[89,59,79,53],[90,0,255,0],[91,170,255,170],[92,0,189,0],
	[93,126,189,126],[94,0,129,0],[95,86,129,86],[96,0,104,0],[97,69,104,69],[98,0,79,0],[99,53,79,53],[100,0,255,63],
	[101,170,255,191],[102,0,189,46],[103,126,189,141],[104,0,129,31],[105,86,129,96],[106,0,104,25],[107,69,104,78],
	[108,0,79,19],[109,53,79,59],[110,0,255,127],[111,170,255,212],[112,0,189,94],[113,126,189,157],[114,0,129,64],
	[115,86,129,107],[116,0,104,52],[117,69,104,86],[118,0,79,39],[119,53,79,66],[120,0,255,191],[121,170,255,234],
	[122,0,189,141],[123,126,189,173],[124,0,129,96],[125,86,129,118],[126,0,104,78],[127,69,104,95],[128,0,79,59],
	[129,53,79,73],[130,0,255,255],[131,170,255,255],[132,0,189,189],[133,126,189,189],[134,0,129,129],[135,86,129,129],
	[136,0,104,104],[137,69,104,104],[138,0,79,79],[139,53,79,79],[140,0,191,255],[141,170,234,255],[142,0,141,189],
	[143,126,173,189],[144,0,96,129],[145,86,118,129],[146,0,78,104],[147,69,95,104],[148,0,59,79],[149,53,73,79],
	[150,0,127,255],[151,170,212,255],[152,170,212,255],[153,126,157,189],[154,0,64,129],[155,86,107,129],[156,0,52,104],
	[157,69,86,104],[158,0,39,79],[159,53,66,79],[160,0,63,255],[161,170,191,255],[162,0,46,189],[163,126,141,189],
	[164,0,31,129],[165,86,96,129],[166,0,25,104],[167,69,78,104],[168,0,19,79],[169,53,59,79],[170,0,0,255],[171,170,170,255],
	[172,0,0,189],[173,126,126,189],[174,0,0,129],[175,86,86,129],[176,0,0,104],[177,69,69,104],[178,0,0,79],[179,53,53,79],
	[180,63,0,255],[181,191,170,255],[182,46,0,189],[183,141,126,189],[184,31,0,129],[185,96,86,129],[186,25,0,104],
	[187,78,69,104],[188,19,0,79],[189,59,53,79],[190,127,0,255],[191,212,170,255],[192,94,0,189],[193,157,126,189],
	[194,64,0,129],[195,107,86,129],[196,52,0,104],[197,86,69,104],[198,39,0,79],[199,66,53,79],[200,191,0,255],
	[201,234,170,255],[202,141,0,189],[203,173,126,189],[204,96,0,129],[205,118,86,129],[206,78,0,104],[207,95,69,104],
	[208,59,0,79],[209,73,53,79],[210,255,0,255],[211,255,170,255],[212,189,0,189],[213,189,126,189],[214,129,0,129],
	[215,129,86,129],[216,104,0,104],[217,104,69,104],[218,79,0,79],[219,79,53,79],[220,255,0,191],[221,255,170,234],
	[222,189,0,141],[223,189,126,173],[224,129,0,96],[225,129,86,118],[226,104,0,78],[227,104,69,95],[228,79,0,59],
	[229,79,53,73],[230,255,0,127],[231,255,170,212],[232,189,0,94],[233,189,126,157],[234,129,0,64],[235,129,86,107],
	[236,104,0,52],[237,104,69,86],[238,79,0,39],[239,79,53,66],[240,255,0,63],[241,255,170,191],[242,189,0,46],
	[243,189,126,141],[244,129,0,31],[245,129,86,96],[246,104,0,25],[247,104,69,78],[248,79,0,19],[249,79,53,59],
	[250,51,51,51],[251,80,80,80],[252,105,105,105],[253,130,130,130],[254,190,190,190],[255,255,255,255]]
end

def help 
	"
	SUPPORTED DXF ENTITIES ARE:
	 
	 1.  Polyline's as connected edges.
	 2.  Polyline's (closed) as user selected faces.
	 3.  LWPolylines as connected edges.
	 5.  Lines as edges.
	 6.  Circles as a circle of connected edges.
	 7.  Arcs as an arc of connected edges.
	 8.  3dFaces as faces.
	 9.  Blocks as groups or components.
	10. Polyline mesh as edges.
	11. Polyline mesh as user selected faces.
	
	BLOCKS import as groups, or components. Their layers are 
	maintained, and the group's, or component's name that is inserted 
	into Sketchup is the dxf file name. Dxf block names are the original 
	Cad's ""Drive\\Path\\FileName.Ext"" name. Nested blocks are not
	supported.
	
	FACES include their layers and materials (see below). 3DFaces, and
	closed polylines (default option) are imported as faces. Holes within
	a face are faced by default, and the user must inspect the model and
	manually remove them.
	
	LAYERS AND MATERIALS: The default import option for faces 
	are with layer names, and dxf colors import as SU materials. If the user
	is able to set the Cad file color, or material with the basic Sketchup 
	material, or the current Sketchup model material's, the options to 
	support this are available.

	IMPORT ORIGIN for model, or user selected origin is provided. 
	Model origin simply places the imported model's origin on the Sketchup
	origin. This is usefull when the Cad, and Sketchup models are identical.
	
	UNSUPPORTED GEOMETRIC ENTITIES include polyface mesh, 
	and (nested blocks). LWPolyline bulge, and width is also not supported.
	If you require these or other unsupported entities, explode them into 
	their basic parts before creating the dxf.  TIG has published a Dxf text
	importer for Sketchup.
	
	ERROR MESSAGES provides the option to Cancel the message. 
	When selected, and if possible, the application will skip the problem,
	and not display additional error messages."

end

unless file_loaded? File::basename(__FILE__)
	add_separator_to_menu("File")	
    UI.menu("File").add_item("Import DXF") { atelier_main_proc }
    file_loaded File::basename(__FILE__)
end
