import .dwg file to solidworks part file
Posted: Thu Jul 18, 2024 9:24 am
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
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