SW: Multiple dxf export from 3D

Hi all

I'm looking for a macro to perform .dxf exports of all the 3D present in a file. Let me explain, all my 3D sheet metal files are in a customer folder and I would like it to unfold each part when I run the macro and save it as a .dxf file sheet metal option. 

I looked at what existed on the net, but I couldn't find an equivalent to my research. 

Thanks in advance

Hello

Look at the task scheduler to see if there are a few things.

Batch converter (tool of the mycadservices premium suite)

1 Like

Explanation here, see at the end of the video for the options for exporting sheet metal parts in dxf:  http://youtu.be/wJeSg5cO06s

1 Like

Unfortunately, I only have the standard version of SW, so I wanted to go through a macro.

Here is the basic function included in Solidworks (without the need for a third-party tool...):

DXF-DWG Export - Page 1

DXF-DWG Export - Page 2

Then, looking at its functions on the macro side, there should be a way to automate it...

I can't help with the macro side.

Thanks Olivier, I know this method, but when you have a folder of several pieces to transform into a .dxf it's super long...

So I wanted the same way as this macro => dwg to pdf but to go from Sldprt to .dxf

 

 

Hello

Here is a snippet of code that allows you to record, from a sldprt, the unfolded of a sheet metal in dxf.

Sub main()

    Dim swApp As SldWorks.SldWorks
    Dim swmodel As SldWorks.ModelDoc2
    Dim stPath As String
    Dim lgFichier As Long
    Dim blretval As Boolean
    
    Set swApp = Application.SldWorks

    'on récupére le document actif
    Set swmodel = swApp.ActiveDoc
    
    If Not swmodel Is Nothing Then
       'on vérifie que le fichier est enregisté
        If swmodel.GetPathName = "" Then
            MsgBox "Veuillez enregistrer votre document avant de lancer la macro", vbInformation
            End
        Else
            'on récupére l'emplacement du fichier
            stPath = swmodel.GetPathName

            'on récupére le nombre de caractére jusqu'au . de l'extension
            lgFichier = InStrRev(stPath, ".", -1, vbTextCompare) - 1
            'on récupére le chemin sans l'extention
            If lgFichier > 0 Then
                  stPath = Left(stPath, lgFichier)
            End If
        End If
        
        'si le document est une pièce
        If swmodel.GetType = swDocPART Then
           'on créer le déplié
            blretval = swmodel.ExportFlatPatternView(stPath & ".DXF", 1)
            'on créer le DXF
            blretval = swmodel.SaveAs3(stPath & ".DXF", 0, 0)
        End If
    End If

End Sub

 

You still have to write the code for the analysis part of the folder, loading the part and then closing this part.

Kind regards

2 Likes

Thank you for your help,

My program is now working! It opens, saves the dxf, and closes all parts in the selected folder.

I share

 

 

'-------------------------------------------------------------------------------------------------------------


Option Explicit

Private Const BIF_RETURNONLYFSDIRS As Long = &H1
Private Const BIF_DONTGOBELOWDOMAIN As Long = &H2
Private Const BIF_RETURNFSANCESTORS As Long = &H8
Private Const BIF_BROWSEFORCOMPUTER As Long = &H1000
Private Const BIF_BROWSEFORPRINTER As Long = &H2000
Private Const BIF_BROWSEINCLUDEFILES As Long = &H4000
Private Const MAX_PATH As Long = 260

Function BrowseFolder(Optional Caption As String, Optional InitialFolder As String) As String

Dim SH As Shell32.Shell
Dim F As Shell32.Folder

Set SH = New Shell32.Shell
Set F = SH. BrowseforFolder(0&, Caption, BIF_RETURNONLYFSDIRS, InitialFolder)
If Not F Is Nothing Then
    If F = "Desktop" Then
        BrowseFolder = About("USERPROFILE") & "\Desktop"
    Else
        BrowseFolder = F.Items.Item.Path
    End If
End If

End Function

Sub main()
Dim swApp        As SldWorks.SldWorks
Dim swmodel      As SldWorks.ModelDoc
Dim sFileName    As String
Dim Path         As String
Dim nErrors      As Long
Dim nWarnings    As Long
Dim swPart       As SldWorks.PartDoc
Dim PartNoDes    As String
Dim stPath As String
Dim lgFile As Long
Dim blretval As Boolean


    Set swApp = Application.SldWorks
   ' Set swExportPDFData = swApp.GetExportFileData(1)
  
    
    Path = BrowseFolder("Select a Path/Folder")
    If Path = "" Then
        MsgBox "Please select the path and try again"
        End
    Else
    Path = Path + "\"
    End If
         
    sFileName = Dir(Path & "*.sldprt")
    Do Until sFileName = ""
        Set swmodel = swApp.OpenDoc6(Path + sFileName, swDocPART, swOpenDocOptions_Silent, "", nErrors, nWarnings)
        Set swmodel = swApp.ActiveDoc
        Set swPart = swApp.ActiveDoc
           
                   If swmodel. GetPathName = "" Then
            MsgBox "Please save your document before launching the macro", vbInformation
            End
        Else
            'we get the location of the file
            stPath = swmodel. GetPathName

            'we get the number of characters up to . of the extension
            lgFile = InStrRev(stPath, ".", -1, vbTextCompare) - 1
            'we recover the path without the extension
            If lgFile > 0 Then
                  stPath = Left(stPath, lgFile)
            End If
        End If
        
        'If the document is a document
        If swmodel. GetType = swDocPART Then
           'we create the unfolded
            blretval = swmodel. ExportFlatPatternView(stPath & ". DXF", 1)
            The DXF was created
            blretval = swmodel. SaveAs3(stPath & ". DXF", 0, 0)
        End If
           
             swApp.QuitDoc swPart.GetPathName
        Set swPart = Nothing
        Set swmodel = Nothing
        sFileName = Dir
    Loop

MsgBox "All Done"
End Sub

'-------------------------------------------------------------------------------------------------------------

4 Likes