import .dwg file to solidworks part file

Several announcements for new users.
Mahaveer981
Posts: 2
Joined: Thu Jul 18, 2024 7:57 am
Answers: 0
x 1

import .dwg file to solidworks part file

Unread post 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
User avatar
gupta9665
Posts: 405
Joined: Thu Mar 11, 2021 10:20 am
Answers: 25
Location: India
x 426
x 445

Re: import .dwg file to solidworks part file

Unread post 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.
Deepak Gupta
SOLIDWORKS Consultant/Blogger
Mahaveer981
Posts: 2
Joined: Thu Jul 18, 2024 7:57 am
Answers: 0
x 1

Re: import .dwg file to solidworks part file

Unread post by Mahaveer981 »

didn't get the 2nd point...can you please brief it
Post Reply