I'm just chasing some help with my batch export to DXF's that I've created recently and if anybody has any ideas it would be a great help.
The Macro is designed to traverse the main assembly, finding sheet metal parts and then exporting them as DXF's. I've been trying to make it quicker and quicker as even a small improvement makes a big difference when its run on some of our larger assemblies. I have had it working well with the ExportToDWG2 method and using the ActivateDoc3 method to open the part, but its a lot slower than the current method I'm trialing, which uses the OpenModelDoc6 method. However the ExportToDWG2 method doesn't appear to be working with the OpenModelDoc6 method so instead I use ExportFlatPatternView method which at first seems to work and is soooo much faster. But when I open up the DXF's which this method exports the scale is always wrong whether it be 5:1 or 10:1 or something similar. I would be happy with the ActivateDoc3 method but the OpenModelDoc6 method is a lot faster it would appear to the point that for the same assembly the ActivateDoc4 method will take 870 seconds and the OpenModelDoc6 method will take 84 seconds.
I've done some research and there are a few places such as here where people have addressed the wrong scale issue such as here,(https://forum.solidworks.com/thread/108728) but no answers other than to use ExportToDWG2 which doesn't appear to work with OpenModelDoc6.
I'll attach my current code, feel free to use it and please excuse my terrible formatting
The Macro does a few things that I've found weren't included in other I've found, such as doing checks to see if the Default Parameters are overidden anywhere in the sheetmetal feature and flange. It also has a few places where it will avoid exporting the same file more than once if you have several of the same component in the same assembly. It also has a userform which is used for status feedback and an estimated time to completion for those larger assemblies. It includes the material, thickness, bendradius in the title of the file, which is then saved within a folder called DXF in the parent directory of the main assembly.
The Macro Code structure:
- The macro checks if its dealing with a component or an assembly (where the macro was called)
- if its a component then its exported with a dedicated function, which I don't really have problems with (It will only take a second or two)
- if it isn't a component then the Assembly is traversed and any sheet metal parts within it have their Filepaths and the ExportFilename saved into two arrays
- the Export function is then called which loops through the two arrays and exports the files. The storing of the filepaths only takes a few seconds and allows me to work out how many parts need to be exported, from their you can setup progress reports to the userform.
So my main question would be, does anybody know how to get ExportToDwg2 working with OpenModelDoc6 method? or alternatively, help fix the scaling issue with the ExportFlatPattern method.
The Exporting Section
Public Function ExportDXFs()
Dim i As Integer
Dim loptions As Long
Dim lerrors As Long
Dim swApp As SldWorks.SldWorks
Dim swOpenModel As SldWorks.ModelDoc2
Dim swModelDocExt As SldWorks.ModelDocExtension
Dim longstatus As Long
Dim longwarnings As Long
Set swApp = Application.SldWorks
For i = 1 To Counter
If Dir(PathExport(i)) <> "" Then
n = n + 1
ReDim Preserve Skipped(n)
Skipped(n) = PathOpen(i)
Message_Return PathOpen(i) & " Skipped due to already existing in target"
'Set swOpenModel = swApp.OpenDoc6(PathOpen(i), swDocumentTypes_e.swDocPART, swOpenDocOptions_Silent, "", _
'Set swModelDocExt = swOpenModel.Extension
swApp.SetUserPreferenceIntegerValue swUserPreferenceIntegerValue_e.swDxfOutputNoScale, 1
Set swOpenModel = swApp.ActivateDoc3(PathOpen(i), True, loptions, lerrors)
swOpenModel.ExportToDWG2 PathExport(i), PathOpen(i), 1, True, varalignment, False, False, options, Null
'swOpenModel.ExportFlatPatternView PathExport(i), swExportFlatPatternOption_None
'swModelDocExt.SaveAs PathExport(i), 0, 0, Nothing, longstatus, longwarnings
Message_Return PathOpen(i) & " file exported"
l = l + 1
I'm using Solidworks 2016 64bit with SP3
ExportDxf (Testing).swp.zip 55.4 KB