Hi
Is there a way to export several components en masse from a Sketchup model to DWG files without having to export them first as SKP models and converting each SKP models to DWG files one by one by hand?
Regards
Guillaume
Hi
Is there a way to export several components en masse from a Sketchup model to DWG files without having to export them first as SKP models and converting each SKP models to DWG files one by one by hand?
Regards
Guillaume
What are you starting with? You are asking this question in a SketchUp forum that implies you have a SketchUp model already.
I modeled everything from scratch with SketchUp and my supplier needs every component in DWG files in order to CNC the parts.
Do you mean separate dwg files for each component?
Exactly
OK. There isn’t a native way to export separate .dwgs of the individual objects. You could export an .stl file of a selected object, select another one and make another export. Then you might be able to find a batch converter from .stl to .dwg or maybe .dxf.
What is it you’re modeling and how is the cutting to be done?
I’m modeling a set of furniture parts (150-200 components) made of flat prefinished panels (melamine).
The parts will be machined with an industrial CNC router.
There are applications that can import a SketchUp model file and lay out the parts for CNC cutting. Look at Get Fabber as well as Vectric CNC applications.
Maybe not the finest work of all times but I came up with a bit of ruby that exports all select component definitions of the component instances selected:
path = "R:\\SKP"; model_path = Sketchup.active_model.path; Sketchup.active_model.selection.grep( Sketchup::ComponentInstance ).map {|i| i.definition}.uniq.each {|d| d.save_copy(path+"\\"+d.name+".skp")}.map {|d| path+"\\"+d.name+".skp"}.each {|p| puts p; Sketchup.open_file(p, with_status: true); Sketchup.active_model.active_view.zoom_extents; Sketchup.active_model.export(p+".dwg")}; Sketchup.open_file(model_path, with_status: true)
It seems to work, takes a while to iterate over every file. I’m just posting it here in case it helps someone in the future (yes I’m speaking of you who came straight from Google looking for this).
Regards
Guillaume
Guillaume. You have created exactly what I need as I have over 100 components to export to .dwg
Unfortunately. I have never used the Ruby console before.
I selected about 30 of the components in my drawing and opened the console window and pasted in your code. I hit enter and the status bar progressed and then seemed to finish. My question is… where are the files exported to?
Thank you in advance for your help on this.
Hugo
EDIT - I worked it out in the end. Simple really. I just needed to change the drive letter from “R” to “C” (as I don’t have an R drive in this PC).
“R:\SKP” = “C:\SKP”
Thank you Guillaume. You saved me hours of tedious work
I’ve tune it up so it asks for export folder and after its done it close all tabs it has created and opened.
require 'fileutils'
require 'sketchup.rb'
# Zeptej se uĹľivatele na cestu k exportnĂmu adresáři
export_path = UI.select_directory(title: 'Vyberte exportnà adresář')
exit if export_path.nil? # Uživatel zrušil výběr adresáře
model_path = Sketchup.active_model.path
created_files = []
begin
Sketchup.active_model.selection
.grep(Sketchup::ComponentInstance)
.map { |i| i.definition }
.uniq
.each do |d|
file_name = File.join(export_path, "#{d.name}.skp")
d.save_copy(file_name)
created_files << file_name
puts file_name
Sketchup.open_file(file_name, with_status: true)
Sketchup.active_model.active_view.zoom_extents
dxf_file_name = File.join(export_path, "#{d.name}.dxf")
Sketchup.active_model.export(dxf_file_name)
end
ensure
# Uzavři všechny soubory, které byly vytvořeny
created_files.each { |file| Sketchup.active_model.close(true) if File.exist?(file) }
end
Sketchup.open_file(model_path, with_status: true)