AnsweredAssumed Answered

2016 broke my macro that was written for 2014, help

Question asked by Tyler Holden on Nov 11, 2015
Latest reply on Nov 11, 2015 by Deepak Gupta

My macro as shown below, worked great in 2014, it is broken in 2016.  I click the macro button and solidworks sits there frozen and i end up having to close it and restart solidworks.  Please advise. 

 

 

 

'Export Drawing as DXF_PDF (Revision).swp ------------- 01/29/15

 

 

'Description: Macro to save active drawing as PDF and DXF.

 

 

'Pre-Condition: An open drawing with one view.

 

 

'Post-Condition: Macro save active drawing as PDF and DXF in specified location with referenced model file name

'                along with drawing revision as exported file name in the file name.

 

 

'Please back up your data before use and USE AT OWN RISK

 

 

' This macro is provided as is.  No claims, support, refund, safety net, or

' warranties are expressed or implied.  By using this macro and/or its code in

' any way whatsoever, the user and any entities which the user represents,

' agree to hold the authors free of any and all liability.  Free distribution

' and use of this code in other free works is welcome.  If any portion of

' this code is used in other works, credit to the authors must be placed in

' that work within a user viewable location (e.g., macro header).  All other

' forms of distribution (i.e., not free, fee for delivery, etc.) are prohibited

' without the expressed written consent by the authors.  Use at your own risk!

' ------------------------------------------------------------------------------

' 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 swExportPDFData As SldWorks.ExportPdfData

Dim nErrors         As Long

Dim nWarnings       As Long

Dim Revision        As String

Dim PartNumber      As String

Dim nFileName       As String

Const Path          As String = "\\WDMYCLOUDMIRROR\Public\QuadM Release Drawings" 'Change the path here

 

 

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

 

 

Revision = swDraw.CustomInfo("Revision")

If Revision = "" Then

        Revision = ""

End If

 

 

Set swExportPDFData = swApp.GetExportFileData(1)

swExportPDFData.ViewPdfAfterSaving = False

 

 

 

 

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

 

 

'Get Model Name

PartNumber = Mid(swModel.GetPathName, InStrRev(swModel.GetPathName, "\") + 1)

PartNumber = Left(PartNumber, InStrRev(PartNumber, ".") - 1)

 

 

nFileName = Path & "\" & PartNumber & " " & Revision

 

 

'Save as DXF

swDraw.SaveAs3 nFileName & ".DXF", 0, 0

 

 

'Save as PDF`

swDraw.SaveAs3 nFileName & ".PDF", 0, 0

 

 

End Sub

Outcomes