Import DWG files using SketchUp API

Hi Everyone,
Is it possible to import a DWG file in SketchUp using ruby API or C API? If possible, kindly suggest how it can be done. I’m exploring the SketchUp API but couldn’t find anything helpful.

The Model #import method is used to load a file by recognizing the file extension and calling appropriate importer.

See the Importer Options file for information on creating a valid hash for the various importers.

1 Like

Thanks for your response @dezmo

This is what I’m doing. Refer the code snippet below:

model = Sketchup.active_model

options = { :import_materials => true,
:merge_coplanar_faces => false,
:orient_faces => true,
:preserve_origin => true,
:show_summary => true }

filepath = “c:\Users\tks\Desktop\Sample AutoCAD\SampleDrawing.dwg”
status = model.import(filepath , options )

It gives me below results:
Imported elements
Import Failed

Can you please suggest what I’m missing here?

I tried your code with a different filepath and it works for me…
Maybe the space between Sample and AutoCAD could be the problem?
Have you tried to import the file by SketchUp menu import option?

This is your problem.

In double quoted string literals the \ is used to escape characters.
The \U is for inserting Unicode sequences.
The \t is a TAB character.
etc.

See: Ruby Doc - String Literals

Use either:

  • single quoted strings
  • forward slashes instead of backslashes
  • or escape the backslash as in "C:\\Users\\tks\\Desktop\\SampleDrawing.dwg"
1 Like

Thanks for pointing that out. I shouldn’t have just copy pasted the path. It made unnecessary issues.

1 Like