4

I am trying to open a .dwg file in SolidWorks 2015. I have been succsesfully able to open a .slddrw by using

IModelDoc2 doc = swApp.OpenDoc6("C:/Temp/BlankDraw.SLDDRW", (int)swDocumentTypes_e.swDocDRAWING, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", 0, 0);

The issue becomes when I replace the .slddrw portion with a .dwg, it returns null.

Is there a way a different way I need to look into to open the .dwg?

Cogorlopez
  • 63
  • 1
  • 9
  • SOLIDWORKS isn't going to do a great job opening a dwg file. If you open it manually, there is usually a conversion process. What are you attempting to accomplish? You may need the eDrawings API or something else. – AndrewK Sep 29 '16 at 20:17
  • @AndrewK I am trying to develop a program that will convert our .dwg's to .tif's. After spending sometime trying to do this with SolidWorks it doesn't seem as easy as we thought because SolidWorks doesn't play nicely with .dwg's – Cogorlopez Oct 03 '16 at 15:59
  • I would suggest trying the eDrawings API...That will handle the 2D drawing better and i know the UI allows for an easy save to .tif – AndrewK Oct 03 '16 at 16:03

2 Answers2

3

The SOLIDWORKS API recommends using the method ISldWorks::LoadFile4 to load non-native files.

This is what the API docs say aboot dwg files with the LoadFile4.

DXF/DWG files:

You can:

Let SOLIDWORKS determine the default values:

Paper size and sheet scale are computed to fit the input data.

Length unit is determined from the header of the input DXF/DWG file.

Sheet name is the same as the layout name in the input DXF/DWG file.

  • or -

Set your own values by using:

ISldWorks::GetImportFileData to obtain the IImportDxfDwgData interface.

Use the following methods with a Sheet argument of "" (an empty string) to set up your defaults before loading the file:

IImportDxfDwgData::GetPaperSize

IImportDxfDwgData::GetPosition

IImportDxfDwgData::GetSheetScale

IImportDxfDwgData::ImportMethod

IImportDxfDwgData::LengthUnit

IImportDxfDwgData::SetPaperSize

IImportDxfDwgData::SetPosition

IImportDxfDwgData::SetSheetScale

IImportDxfDwgData::SheetName

See IImportDxfDwgData for details about importing DXF/DWG data.

NOTES:

Getting the IImportDxfDwgData interface does not get default values from the input file. Any values not set by you are set to the values computed by SOLIDWORKS.

If the DWG/DXF file has multiple sheets, use these methods with a valid layout name in the Sheet argument to set up sheet specific settings, which overrides the default settings. If any of the individual items are not specified for a given layout name, the value used is from the defaults (layout name ""). If the default value is not specified, SOLIDWORKS computes and uses a meaningful value for that item.

Community
  • 1
  • 1
Amen Jlili
  • 1,884
  • 4
  • 28
  • 51
3

Simple as:

    Option Explicit
    Dim swApp As Object

    Dim Part As Object
    Dim boolstatus As Boolean
    Dim longstatus As Long, longwarnings As Long

    Sub main()

    Set swApp = Application.SldWorks

    boolstatus = swApp.LoadFile2("T:\Debug-LstBlock.dwg", "11 0")
    Set Part = swApp.ActiveDoc
    End Sub