Hi all,
I've been using the below macro from Deepak for a little while and have tried to add extra functionality that would make this an indispensable tool for our workflow.
I would like to:
Export .DXF of current active sheet only
Export .PDF of current active sheet only (currently exports all sheets)
Allow input of file name to be identical for both (ie. myexport. pdf and myexport.dxf) and for them to be exported to the same directory that the open drawing is saved in.
As a bonus I'd love it to be able to string together 2x custom properties with a dash in between as the export filename ("POC" - "PARTNUMBER".pdf/dxf) so we didn't need to enter it all manually
I've seen all the various components in different macros but have failed to bring them together in one package. Can anyone help? Thanks in advance, and please bear in mind I have very little knowledge of VB.
' ------------------------------------------------------------------------------
' Written by: Deepak Gupta (http://gupta9665.com/)
' -------------------------------------------------------------------------------
Option Explicit
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swDrawModel As SldWorks.ModelDoc2
Dim swDraw As SldWorks.DrawingDoc
Dim swView As SldWorks.View
Dim nErrors As Long
Dim nWarnings As Long
Set swApp = Application.SldWorks
Set swDrawModel = swApp.ActiveDoc
' Check to see if a drawing is loaded.
If swDrawModel Is Nothing Then
MsgBox "There is no active drawing document"
Exit Sub
End If
If swDrawModel.GetType <> swDocDRAWING Then
MsgBox "Open a drawing first and then TRY again!"
Exit Sub
End If
Set swDraw = swDrawModel
Set swView = swDraw.GetFirstView
Set swView = swView.GetNextView
Set swModel = swView.ReferencedDocument
' Determine if there is any view
If swModel.GetPathName = "" Then
MsgBox "Insert a View first and then TRY again!"
Exit Sub
End If
'Save as DXF
swDraw.SaveAs3 Left(swDraw.GetPathName, InStrRev(swDraw.GetPathName, ".") - 1) & ".DXF", 0, 0
'Save as PDF
swDraw.SaveAs3 Left(swDraw.GetPathName, InStrRev(swDraw.GetPathName, ".") - 1) & ".PDF", 0, 0
End Sub