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