Export DXF macro
Export DXF macro
(OP)
I am using the macro from this thread:
https://www.eng-tips.com/viewthread.cfm?qid=328477...
Changed a little bit into this:
Option Explicit
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim vConfNameArr As Variant
Dim sConfigName As String
Dim nStart As Single
Dim i As Long
Dim bShowConfig As Boolean
Dim bRebuild As Boolean
Dim bRet As Boolean
Set swApp = CreateObject("SldWorks.Application")
Set swModel = swApp.ActiveDoc
vConfNameArr = swModel.GetConfigurationNames
For i = 0 To UBound(vConfNameArr)
sConfigName = vConfNameArr(i)
bShowConfig = swModel.ShowConfiguration2(sConfigName)
bRebuild = swModel.ForceRebuild3(False)
Dim FilePath As String
Dim PathSize As Long
Dim PathNoExtension As String
Dim NewFilePath As String
FilePath = swModel.GetPathName
PathSize = Strings.Len(FilePath)
PathNoExtension = Strings.Left(FilePath, PathSize - 6)
NewFilePath = sConfigName & ".DXF"
'Export Flat Pattern
bRet = swModel.ExportFlatPatternView(NewFilePath, 1)
Next i
End Sub
Now the problem I have with this is:
When before running the macro (in Solidworks 2020) I save a random drawing, my export macro uses the scale of that drawing to export the dxf.
So I save a drawing with scale 1:2
I run the macro in part environment
The part is for example 100x100mm
The exported dxf has dimensions 200x200.
Ofcourse I want to export only 1:1, independend of the non related drawings I save.
Thanks for any help.
https://www.eng-tips.com/viewthread.cfm?qid=328477...
Changed a little bit into this:
Option Explicit
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim vConfNameArr As Variant
Dim sConfigName As String
Dim nStart As Single
Dim i As Long
Dim bShowConfig As Boolean
Dim bRebuild As Boolean
Dim bRet As Boolean
Set swApp = CreateObject("SldWorks.Application")
Set swModel = swApp.ActiveDoc
vConfNameArr = swModel.GetConfigurationNames
For i = 0 To UBound(vConfNameArr)
sConfigName = vConfNameArr(i)
bShowConfig = swModel.ShowConfiguration2(sConfigName)
bRebuild = swModel.ForceRebuild3(False)
Dim FilePath As String
Dim PathSize As Long
Dim PathNoExtension As String
Dim NewFilePath As String
FilePath = swModel.GetPathName
PathSize = Strings.Len(FilePath)
PathNoExtension = Strings.Left(FilePath, PathSize - 6)
NewFilePath = sConfigName & ".DXF"
'Export Flat Pattern
bRet = swModel.ExportFlatPatternView(NewFilePath, 1)
Next i
End Sub
Now the problem I have with this is:
When before running the macro (in Solidworks 2020) I save a random drawing, my export macro uses the scale of that drawing to export the dxf.
So I save a drawing with scale 1:2
I run the macro in part environment
The part is for example 100x100mm
The exported dxf has dimensions 200x200.
Ofcourse I want to export only 1:1, independend of the non related drawings I save.
Thanks for any help.
RE: Export DXF macro
Either set that option before running the macro, or add that option into your code.
RE: Export DXF macro
Deepak Gupta
SOLIDWORKS Champion and Expert
SW 2022 SP0.0, 2021 SP5.1 and 2020 SP5.0
Boxer's SOLIDWORKS Blog
RE: Export DXF macro
@TheTick I know I can select scale options when exporting drawings as DXF. This function is disabled when exporting from a part. I really wouldnt know how to add this into my code.
If someone could help me with that, would be apreciated.
@Gupta65: I tried that, but this doesn't work.
The workaround we do now is simply saving a drawing scale 1:1 everytime before exporting, but Im looking for an option to just add this in the macro.
Thanks,
RE: Export DXF macro
I prefer exporting from part, as it gives control over the origin. I can export multiple DXFs that cam be overlaid with the same origin.
RE: Export DXF macro
The point is that I would expect my part to export 1:1, but it doesn`t when I use the macro. It does when I use the Export to dxf / dwg command.
RE: Export DXF macro
Deepak Gupta
SOLIDWORKS Champion and Expert
SW 2022 SP0.0, 2021 SP5.1 and 2020 SP5.0
Boxer's SOLIDWORKS Blog
RE: Export DXF macro
Drawing template 1
Link
Drawing template 2
Link
Part
Link
Is this what you are asking for?
RE: Export DXF macro
Deepak Gupta
SOLIDWORKS Champion and Expert
SW 2022 SP0.0, 2021 SP5.1 and 2020 SP5.0
Boxer's SOLIDWORKS Blog