Preview of DXF created in macro

Hello 

 

First of all I hope I'm in the right section and apologize if it's not the case, I'm only starting on the forum.

 

My question is this, I have a macro that saves my part in dxf format in a location that I specify in the macro. 

So far so good, but I'd like to add a little more:

I would like that at the end of the execution of this macro we have a preview of the dxf created.

In the same way in fact as when you register as; .dxf etc. By doing this we have a preview of the DXF created.

 

In case it could be useful, I'll copy my macro below:

This could perhaps also be used for the integration of the preview into the macro.

If anyone has an idea, I'm all for it. No matter how hard I looked, I can't find anything...

 


Sub main()
    Dim swApp As SldWorks.SldWorks
    Dim swmodel As SldWorks.ModelDoc2
    Dim stPath As String
    Dim lgFile As Long
    
    Dim sReference As String
    Dim blretval as Boolean
    Dim Errors As Long
    Dim Warnings As Long
    
    Set swApp = Application.SldWorks
    'Checking out the active document
    Set swmodel = swApp.ActiveDoc
    
    If Not Swmodel Is Nothing Then
       'We check that the file is registered
        If swmodel. GetPathName = "" Then
            MsgBox "Please save your document", vbInformation
            End
        Else
            'we get the location of the file
            stPath = swmodel. GetPathName
            
            
            
            stPath = swmodel. GetPathName' retrieves the display name of the current document
            
          
            sReference = Mid(stPath, InStrRev(stPath, "\") + 1) 'Retrieves everything after the last \
            
        
            
            sReference = Left(sReference, Len(sReference) - 7) 'Removed the 6 characters corresponding to the file extension and the .
            
       
            
            
            stPath = Left(stPath, InStrRev(stPath, "\")) 'Retrieves path without filename
  
            
            '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 developed
            blretval = swmodel. ExportFlatPatternView("C:\Users\Stage-02\Desktop\DXF\" & sReference & ". DXF", 1)
            The DXF was created
            blretval = swmodel. SaveAs3(sReference & ". DXF", 0, 0)
            
            'If the document is a drawing
        ElseIf swmodel. GetType = swDocDRAWING Then
            The DXF was created
            blretval = swmodel. SaveAs3(sReference & "_drw. DXF", 0, 0)
        End If
    
        'we save the file
        blretval = swmodel. Save3(0, 0, 0)
   
    End If

End Sub
 

1 Like

Hello

I don't think a preview is feasible.

I created a macro that goes through a drawing in order to generate a DXF of the unfold which allows you to visualize it for a little moment.

Here is the tutorial in question:

http://www.lynkoa.com/tutos/3d/macro-d-export-deplie-de-piece-en-dxf

If you have any questions, don't hesitate.

Hello

A priori it is not possible, but you can either open the DXF file in SolidWorks or in Windows if another program is planned to open them.

Edit: If you need any of the instructions, please tell me which one and I'll give you the code.

4 Likes

Hello PL

If indeed you have the code to open it in solidworks so that I can integrate it at the end of my macro yes it could interest me

 

Thank you in advance

Hello everyone ! I have already tried to carry out this mission  several times but it remains impossible. I've already looked for different tutorials but it's in vain.