require ‘sketchup.rb’
Directory containing SketchUp models
input_directory_path = “D:/R-and-D/Sketchup”
Directory to save the exported DXF files
output_directory_path = “D:/ModelDFXImages”
Function to save view as a 2D DXF file
def save_2d_dxf(model, view, filename)
options = {
:export_hidden_geometry => true,
:projection => “Parallel”
}
model.export(filename, options)
end
begin
Close all open models
Sketchup.active_model.close(true) while Sketchup.active_model
Iterate through all .skp files in the input directory
Dir.glob(File.join(input_directory_path, “*.skp”)).each do |file_path|
# Open the SketchUp model
model = Sketchup.open_file(file_path)
next unless model # Skip if the file could not be opened
# Create a front view
model.active_view.camera = model.camera.clone.set([0, -1000, 0], [0, 0, 0], [0, 0, 1])
model.active_view.zoom_extents
front_dxf_path = File.join(output_directory_path, "#{File.basename(file_path, ".skp")}_Front_View.dxf")
save_2d_dxf(model, model.active_view, front_dxf_path)
# Create a top view
model.active_view.camera = model.camera.clone.set([0, 0, 1000], [0, 0, 0], [0, 1, 0])
model.active_view.zoom_extents
top_dxf_path = File.join(output_directory_path, "#{File.basename(file_path, ".skp")}_Top_View.dxf")
save_2d_dxf(model, model.active_view, top_dxf_path)
# Close the model without saving changes
model.close
end
puts “2D DXF files have been saved for all models in the specified directory.”
rescue => e
puts “An error occurred: #{e.message}”
puts e.backtrace
end
Faucet_Kitchen 1.skp (464.6 KB)