Convert 3D mass to Dxf while keeping the origin

Hello 

I have several 3D profiles on a part (part family) that I have to convert to DXF and keeping their config name as file name, after trying Batchconverter , I notice that the origin of my part is not included. I tried a macro but it happens to me the same.

The only solution I found is to save under dxf for each configuration. It's long and I have several pieces like this to do. 

Do you have a solution to my problem? 

Thank you.

Kind regards

My macro: 

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 = PathNoExtension + sConfigName & ".DXF"

'Export Flat Pattern
bRet = swModel.ExportFlatPatternView(NewFilePath, 1)

Next i

End Sub

 

 


meule_heller_pour_dxf.sldprt

Hello

The "ExportFlatPatternView" function is obsolete, in your macro you have to use the ExportToDWG2 function and see with the "Alignment" parameter to set the coordinates of the origin and the directions of the axes.

Kind regards

Hello 

Thank you for your answer, 

Do you have an example of how to use it? Because I don't understand it's to export to DWG right?

 

Kind regards.

Hello

As indicated in the function settings, this is for an export in DXF or DWG:

"FilePath : Path and file name of the exported DXF/DWG file"

On the link I gave you there is already an example, see HERE. To save in DXF on this example, just change the line sPathName = sPathName + "dwg" to sPathName = sPathName + "dxf".

Kind regards

Hello 

Ok I'm not good enough for macros.  ^^

If I want the dxf to be created at the file location of my 3D I have to touch something? and I would like the macro to create a DXF for each configuration

If you have the time, of course

 

Kind regards.

Here's an example based on your macro:

Option Explicit

Sub main()

    Dim swApp                   As SldWorks.SldWorks
    Dim swModel                 As SldWorks.ModelDoc2
    Dim swPart                  As SldWorks.PartDoc
    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
    Dim varAlignment            As Variant
    Dim dataAlignment(11)       As Double
    Dim varViews                As Variant
    Dim dataViews(0)            As String

    Set swApp = CreateObject("SldWorks.Application")
    Set swModel = swApp.ActiveDoc
    
    swModel.ShowNamedView2 "*Face", 1
    swModel.ViewZoomtofit2
    
    dataAlignment(0) = 0#
    dataAlignment(1) = 0#
    dataAlignment(2) = 0#
    dataAlignment(3) = 1#
    dataAlignment(4) = 0#
    dataAlignment(5) = 0#
    dataAlignment(6) = 0#
    dataAlignment(7) = 1#
    dataAlignment(8) = 0#
    dataAlignment(9) = 0#
    dataAlignment(10) = 0#
    dataAlignment(11) = 1#

    varAlignment = dataAlignment

    varViews = dataViews

    vConfNameArr = swModel.GetConfigurationNames

    For i = 0 To UBound(vConfNameArr)

        sConfigName = vConfNameArr(i)

        bShowConfig = swModel.ShowConfiguration2(sConfigName)
        
        bRebuild = swModel.ForceRebuild3(False)

        Dim sPathName As String
        Dim sModelName As String
        
        sModelName = swModel.GetPathName
        
        sPathName = swModel.GetPathName
        sPathName = Left(sPathName, Len(sPathName) - 6)
        sPathName = sPathName + sConfigName + ".dxf"
    
        Set swPart = swModel

        swPart.ExportToDWG2 sPathName, sModelName, swExportToDWG_ExportAnnotationViews, False, varAlignment, False, False, 0, varViews

    Next i

End Sub

Kind regards

1 Like

Thank you very much. 

This will help me in my work and especially in my learning of VBA code. 

Kind regards

Hello 

I allow myself to rewrite about this macro, indeed I want to improve it by selecting the folder where it should save but I block it a little there, I can select the folder but it still saves where the file is. 

What piece of code am I missing? I'm trying to search on the net but there is so much different code.

Kind regards.


dxf.swp