How can I create 2D file for .skp file with Sketchup ruby API


#1

Hi,
I am trying to create 2D file for .skp file (Sketchup file) using Sketchup ruby API. Basically my requirement is to convert .skp 3d file into any 2d file which can have any extension with correct measurements. Can anyone help me or please give me some idea to solve this issue?


#2

Without specifying a format, you could do Sketchup.active_model.active_view.write_image("filename.png", 100, 100), which is 2D.

Assuming you want to write to a vector based format, you would choose the (core) Ruby file writing methods for writing binary or text to a file.

File.open("filename.obj", "wt") { |file| # wt = write, text
  file.puts "v 1 0 0"
  file.puts "v 1 1 0"
  file.puts "v 0 1 0"
  file.puts "f 1 2 3"
}

#3

Thank you Aerilius,its giving picture format of the existing model,but i need file something like Auto CAD file, i need to show my existing model with its all measurements and it should be specific and clear if somebody is checking that file without Sketchup file


#4

See the second part of the reply. If you really want to export to an arbitrary format, you write an exporter that reads information from the model using the SketchUp API and writes it to a file using the Ruby File API. Therefore you need to lookup a specification of the fileformat that you want to implement (from the author/company of the file format).

If you just want to export to one of SketchUp’s supported (3D) formats (like DXF) using one of SketchUp’s included exporters with the configuration options as provided by SketchUp, you can just call Sketchup.active_model.export("filename.dxf").


#5

Hi Aerilius,
‘Sketchup.active_model.export(“filename.dxf”)’. it is fine code,it’s worked for me.
In sketchup(2015) in export -> 2D Grphic -> .jpeg option is there .Manually i used that option and it was working fine.But in ‘Sketchup.active_model.export(“filename.jpeg”)’ it is not giving true output, how can export my model in to .jpeg format?


#6

See the first part of my first reply. If you seriously want to do this via Ruby, you would best also want to follow links, read the given documentation and experiment / try out the obvious.
Sketchup.active_model.active_view.write_image("filename.jpeg", 100, 100)