Page 1 of 1

import .dwg file to solidworks part file

Posted: Thu Jul 18, 2024 9:24 am
by Mahaveer981
I am trying to import .dwg file to a new part as 2D sketch and want to import each layer to a new sketch in solidworks.

I am able to import it as a part but unable to get the sketches.

can you please help me with the macro.

Attaching the macro that I have written.



Option Explicit

Sub main()

'declare variables
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swModelExtension As ModelDocExtension
Dim swPart As SldWorks.PartDoc
Dim bRet1 As Boolean
Dim filename As String
Dim i As Integer
Dim longerrors As Long
Dim vConfigName As Variant

'DWG file path
filename = "" 'some path is given here

Set swApp = Application.SldWorks

'get DWG file data
Dim importData As SldWorks.ImportDxfDwgData
Set importData = swApp.GetImportFileData(filename)

' Import method
importData.ImportMethod("") = SwConst.swImportDxfDwg_ImportMethod_e.swImportDxfDwg_ImportToPartSketch

' Load the specified DWG file
Set swModel = swApp.LoadFile4(filename, "", importData, longerrors)

End Sub

Re: import .dwg file to solidworks part file

Posted: Thu Jul 18, 2024 11:46 am
by gupta9665
I do not see any codes in the API for this option. So I believe this is not implemented yet. Kindly email to your VAR to send this request.

One workaround may be to put each sketch on their own sheet in the DXF file. And during importing, you can specify which sheet to import. And if this works, you can repeat the process for each sheet.

Re: import .dwg file to solidworks part file

Posted: Fri Jul 19, 2024 1:10 am
by Mahaveer981
didn't get the 2nd point...can you please brief it