Reputation: 63
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?
Upvotes: 4
Views: 1345
Reputation: 612
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
Upvotes: 3
Reputation: 1934
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.
Upvotes: 3