Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Export DXF macro

Status
Not open for further replies.

Hermen

Mechanical
Mar 25, 2011
6
I am using the macro from this thread:


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.
 
Replies continue below

Recommended for you

There is an option to export drawings at 1:1.

Either set that option before running the macro, or add that option into your code.
 
Create a new drawing (blank without any sheet format or any tables/notes) and set the scale to 1:1 in that drawing. Now save that drawing as default template undet Tools > Options > Default Template and your parts should export to correct scale.

Deepak Gupta
SOLIDWORKS Champion and Expert
SW 2022 SP0.0, 2021 SP5.1 and 2020 SP5.0
Boxer's SOLIDWORKS Blog


 
Hi,

@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,
 
Exporting from part is automatically 1:1.

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.
 
@TheTick,

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.
 
@Hermen, in that case either you drawing template scale or units are not correct. Can you share one file and your drawing template to check?

Deepak Gupta
SOLIDWORKS Champion and Expert
SW 2022 SP0.0, 2021 SP5.1 and 2020 SP5.0
Boxer's SOLIDWORKS Blog


 
@Hermen, sorry for delayed response. I've checked your files using the codes posted above and result is correct i.e. files are exporting at correct scale. So there seem to be some setting issue in your DXF reader. To check this, open the exported files in edrawings OR back in SW and check the values.

Deepak Gupta
SOLIDWORKS Champion and Expert
SW 2022 SP0.0, 2021 SP5.1 and 2020 SP5.0
Boxer's SOLIDWORKS Blog


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor