Hi, a few year ago, You helped me to do a little plugin to export the outline of selected faces to X:Y coordinates in a text file. (Code below.) Thank you again.
Today, I wanted to separate the arcs, circles and vectors of a selection (I don't need the faces), to export as 2D dxf file (Z=0 for all entities, like for the X:Y plugin below), with three entities (arc, circle, vectors) and be able to use it in a 2D CAD software.
(Some pro laser cutting softwares must have the circle/arc entities to do the cutting interpolation ; if you use only small vectors, like the existing free dxf plugin exporter does, the processing and cutting time could be much much longer, so the price of the cutting is higher.)
It could be a long dxf file, with no groups or order, just one entity after the other, but the circular entities must be described (for example a circle with a center and a radius).
I have the informations to write the elementary dxf file, but I don't know (after search) how to get the initial datas from the selection. For example the center and the radius of a full circle. Could you help me?
I'm french, sorry for the english mistakes. My answers can take one or two days, sorry.
Thank you,
Renaud.
Here is the code of the face2X:Y plugin :
module RenaudIltis
def self.export_face_points
selection = Sketchup.active_model.selection
if selection.empty?
UI.messagebox("Nothing selected, export canceled")
else
# Count how many faces are in the current selection => must be > 0
face_count = 0
# Look at all of the entities in the selection.
selection.each { |entity|
if entity.is_a? Sketchup;;Face
face_count = face_count + 1
end
}
if face_count > 0
# Ask for the file path.
filepath = UI.savepanel("Export selected faces",nil,"*.txt")
# Don't continue when the user cancelled
return if filepath.nil?
# Test of the file extension
filepath = filepath.tr("\\","/")#in case any PC ruby weirdness...
if File.basename(filepath,".*") == File.basename(filepath) #the suffix is right or missing
filepath=File.join(File.dirname(filepath), File.basename(filepath,".txt") + ".txt") #if the suffix is missing or right
else
if File.basename(filepath,".*") + ".txt" != File.basename(filepath)#the suffix is different than .txt
answer = UI.messagebox("Filename has not the '.txt' extension. Change your extension?", MB_YESNO)
if( answer == 6 )
filepath=File.join(File.dirname(filepath), File.basename(filepath,".*") + ".txt")
end
else
filepath=File.dirname(filepath) + "/" + File.basename(filepath,".txt") + ".txt" #if the suffix is missing
end
end
begin
# Open a file for writing
File.open(filepath, "w"){ |file|
selection = Sketchup.active_model.selection
# Get an array of faces that are in the selection.
faces = selection.grep(Sketchup;;Face)
faces.each_with_index{ |face, index|
# Write a label for the face.
file.puts("Face#{index+1}")
# Get a transformation object that translates from model space to 2d space of the face.
t = Geom;;Transformation.axes(face.vertices.first.position, *face.normal.axes).inverse
# Write all vertices to the file.
blnFirstPoint = true
first_point_u=0
first_point_v=0
face.outer_loop.vertices.each{ |vertex|
# Get the point of the vertex and apply the transformation.
point = vertex.position.transform(t)
# Convert the coordinates
u, v = point.to_a.map{ |c| c.to_f }
if blnFirstPoint==true
first_point_u = u
first_point_v = v
blnFirstPoint = false
end #if
# Write the coordinates to the file.
file.puts("#{(u*10000*25.4).to_i.to_f/10000};#{(v*10000*25.4).to_i.to_f/10000}")
}
file.puts("#{(first_point_u*10000*25.4).to_i.to_f/10000};#{(first_point_v*10000*25.4).to_i.to_f/10000}")
}
}
UI.messagebox("The file is here ;" + filepath)
rescue SystemCallError => e
if e.message =~ /(No such file or directory)/
UI.messagebox("Error, the file was not created. Be careful if you are using an older version of SketchUp, the full file path must not contain special characters. The full file path you requested is " + filepath)
else
fail() #re-raise the last exception
end
end
else
UI.messagebox("No faces in the selection, export canceled")
end
end
end
# This will run only once when the file is loaded the first time.
unless file_loaded?(__FILE__)
# Add the method to the menu.
command = UI;;Command.new("Export selected faces to X;Y file"){
self.export_face_points
}
command.small_icon = "faces2xy/faces2xy_icon_16.png"
command.large_icon = "faces2xy/faces2xy_icon_24.png"
command.tooltip = "Export selected faces to X;Y file"
command.menu_text = "Export selected faces to X;Y file"
menu=UI.menu("Plugins")
menu.add_item(command)
tb = UI.toolbar("Selected faces to X;Y")
tb.add_item(command)
if tb.get_last_state == TB_VISIBLE
UI.start_timer(0.1, false) { tb.restore }
elsif tb.get_last_state == TB_NEVER_SHOWN
tb.show
end
file_loaded(__FILE__)
end
end