Export assembly to . DWG

Hello

Is it possible to export a view of an assembly in . DWG? (I arrive with a part, but not with an assembly)

Thank you

Have a nice day

Hello

You would have to temporarily save your assembly in PART to be able to export it in DWG.

1 Like

In fact, for the moment I'm going through the layout.

But I wanted to know if there was a faster one.

Unless you missed something, I don't think so.

Wait for another answer.

1 Like

through a drawing ;-)

simply save the assembly as a part and select all the components, then treat this new part like any traditional part (export to DXF, DWG)

@+ ;-)

1 Like

Basically, that's what I'm already doing^^

So it doesn't get any simpler than that, straight from the assembly.

Thank you for your answers;)

Hello

To avoid all these steps you can also make a small macro that automates the transformation of the asm into prt and then exports it to DWG, it will only take you one click to achieve what you want.

For the backup of the asm in prt it's a simple Part.Saveas3(nomprt, 0, 0) to do and for the export in DWG you should be able to use the macro : http://help.solidworks.com/2016/english/api/sldworksapi/export_part_to_dwg_example_vb.htm

Kind regards

3 Likes

See the attached macro for inspiration.

Kind regards


asmtodwg.swp
2 Likes

The previous macro uses the "ExportFlatPatternView" function which is deprecated and only transfers the front view, this one uses the "ExportToDWG2" replacement function and allows you to create a DWG of each view, I think it will be more in line with what you want to do.

Kind regards


asmtodwg-v2.swp
1 Like

Thank you very much

I never used the Macro, can you explain it to me in two words?

Thank you

asmtodwg-v2.swp doesn't work I have the impression 


screen_shot_10-17-17_at_09.26_am.jpg

Hello

Which version of SW are you on? The libraries loaded in my macro are for SW2017.

In SW, you can do: Tools / Macro / New and copy the code below to replace the one that is automatically written in the new macro then you load a test assembly in SW and finally you do  F5 in the Visual Basic window.

Kind regards

Dim swApp As Object
Public swModel As SldWorks.ModelDoc2

Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long

Sub main()

    Set swApp = Application.SldWorks
    
    Set swModel = swApp.ActiveDoc
    Set Part = swApp.ActiveDoc
    Dim myModelView As Object
    Set myModelView = Part.ActiveView
    myModelView.FrameState = swWindowState_e.swWindowMaximized

    'on récupére le document actif
    Set swModel = swApp.ActiveDoc
    
    If Not swModel Is Nothing Then
       '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
        
        'si le document est un assemblage
        If swModel.GetType = swDocASSEMBLY Then
            'on créer le SLDPRT
            longstatus = Part.SaveAs3(stPath + ".sldprt", 0, 0)
            'On ferme le SDLASM
            swApp.CloseDoc swModel.GetTitle
            'On ouvre le SLDPRT
            Set swModel = swApp.OpenDoc6(stPath + ".sldprt", 1, 0, "", longstatus, longwarnings)
        End If
        
        'si le document est une pièce
        If swModel.GetType = swDocPART Then
            'On l'exporte en DWG
            ExportDWG
        End If
    End If

End Sub

Sub ExportDWG()
    Dim swPart As SldWorks.PartDoc
    Dim sModelName As String
    Dim sPathName As String
    Dim varAlignment As Variant
    Dim dataAlignment(11) As Double
    Dim varViews As Variant
    Dim dataViews(5) As String
    Dim options As Long

    Set swModel = swApp.ActiveDoc

    sModelName = swModel.GetPathName
    sPathName = swModel.GetPathName
    sPathName = Left(sPathName, Len(sPathName) - 6)
    sPathName = sPathName + "dwg"

    Set swPart = swModel

    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

    dataViews(0) = "*En cours"
    dataViews(1) = "*Face"
    dataViews(2) = "*Droite"
    dataViews(3) = "*Gauche"
    dataViews(4) = "*Dessus"
    dataViews(5) = "*Arrière"

    varViews = dataViews

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

 

1 Like

Hello, I record the whole thing in room and then I make a dwg.

Kind regards

1 Like

I'm in 2016 sp3

It still doesn't work.


screen_shot_10-19-17_at_11.49_am.jpg

Hello

That's where the vba annoys me a little ...

Try replacing the lines:

'If the document is a document
If swModel.GetType = swDocPART Then
     'We export it in DWG
     ExportDWG
End If

by:

'If the document is a document
If swModel.GetType = swDocPART Then
     'We export it in DWG
     ExportDWG swModel
End If

Then the line:

Sub ExportDWG

By:

Sub ExportDWG(swModel As SldWorks.ModelDoc2)

And again the line (the one in the Sub ExportDWG(.....):

Set swModel = swApp.ActiveDoc

By:

'Set swModel = swApp.ActiveDoc

Load your assembly and then launch the macro with F5

Kind regards

1 Like

Great thank you d.roger,

it works:D

On the other hand it generates a file for me

How can I get the same macro for the parts alone?

I have a way to modify the macro alone to learn

Hello

For the parts alone it's the same macro since in this one I transform the asm into prt then I launch the transformation into dwg on the prt so you load a part then you launch the macro and you normally  get the 6 DWG created in the Windows folder of the part, At least for me it works too.

Kind regards

1 Like

Thank you very much for your help;)