rocheey
Industrial
- Jan 21, 2001
- 230
It seems there are quite a few threads dealing with exporting DXFs from drawing views, especially when needed for manufacturing. Below is a sample module showing how to parse the geometry from a solidworks view, and how to output your own autocad version 12 compatible dxf file.
This module assumes you are dealing with flat patterns, in any view scale, which need to be 'clean' for toolpathing, etc. While this ripped version ignores linetypes, dimensions, etc, it also ignores the bend lines, datum points, etc which can ruin a machined part.
It also reverses 'flipped' arcs for a true '2d' version of the part. Also some CAM apps dont like the normals reversed in the arcs, so these reversed arcs will 'heal' to boundary-generating routines. (You ever try drawing a CLOCKWISE 3 point arc in acad?)
To use, import the code as its own module, and set up a sample macro something like this:
Sub main()
Dim swApp As SldWorks.SldWorks
Dim Part As ModelDoc2
Dim dwgDoc As DrawingDoc
Dim ExportView As view
Dim DXFName As String
Dim DXFComment As String
Dim success As Boolean
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
If Not (Part.GetType = 3) Then Exit Sub ' not a drawing
Set dwgDoc = Part
Set ExportView = dwgDoc.GetFirstView ' get the 'sheet view'
Set ExportView = ExportView.GetNextView ' get the first view on the sheet
' we have our view, lets export it to a file
DXFName = "C:\SW2DXF.dxf"
' embed a comment in the dxf stating the export date, or something
DXFComment = "Export date: " & Now
success = ViewToDXF(ExportView, DXFName, DXFComment)
End Sub
This module assumes you are dealing with flat patterns, in any view scale, which need to be 'clean' for toolpathing, etc. While this ripped version ignores linetypes, dimensions, etc, it also ignores the bend lines, datum points, etc which can ruin a machined part.
It also reverses 'flipped' arcs for a true '2d' version of the part. Also some CAM apps dont like the normals reversed in the arcs, so these reversed arcs will 'heal' to boundary-generating routines. (You ever try drawing a CLOCKWISE 3 point arc in acad?)
To use, import the code as its own module, and set up a sample macro something like this:
Sub main()
Dim swApp As SldWorks.SldWorks
Dim Part As ModelDoc2
Dim dwgDoc As DrawingDoc
Dim ExportView As view
Dim DXFName As String
Dim DXFComment As String
Dim success As Boolean
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
If Not (Part.GetType = 3) Then Exit Sub ' not a drawing
Set dwgDoc = Part
Set ExportView = dwgDoc.GetFirstView ' get the 'sheet view'
Set ExportView = ExportView.GetNextView ' get the first view on the sheet
' we have our view, lets export it to a file
DXFName = "C:\SW2DXF.dxf"
' embed a comment in the dxf stating the export date, or something
DXFComment = "Export date: " & Now
success = ViewToDXF(ExportView, DXFName, DXFComment)
End Sub