AnsweredAssumed Answered

pdf macro

Question asked by Angelo Flamingo on Dec 9, 2015
Latest reply on Dec 27, 2015 by Deepak Gupta

Hello,

 

I have created a macro to save a drawing as a pdf.  I have it saving in the current directory that the drawing is located as well.  The macro is functioning fine.

 

What I am trying to do now to it is filtering the sheet titles so it only saves certain sheets as the pdf.  Our normal process is leaving the sheet titles as Sheet 1 and so on.  But we also rename only 1 of the sheets as DXF at the end of the sheets.  The DXF sheet is the only one that I want to exclude from the macro.

 

Is this something that is possible?  If so does anyone have a code to perform this part of the macro?  Thank you in advance.  I have listed the macro that I have below.

 

Public Enum swSaveAsOptions_e
    swSaveAsOptions_Silent = &H1    '  Save document silently or not
    swSaveAsOptions_Copy = &H2  '  Save document as a copy or not
    swSaveAsOptions_SaveReferenced = &H4    '  Save referenced documents or not (drawings and parts only)
End Enum
   
    ' Define variable used to hold the SldWorks object
    Dim swApp As SldWorks.SldWorks
    Dim swModel As SldWorks.ModelDoc2
    Dim swDraw As SldWorks.DrawingDoc
    Dim Part As Object
    Dim sFileName As String
    Dim pltName As String
    Dim FNConfigName As Variant 'Name of the configuration (File Name)
    Dim FNCustInfoName As Variant 'Name of field (File Name)
    Dim RevNum As String 'Revision Number of file
    Dim RevConfigName As Variant 'Name of the configuration (Revision)
    Dim RevCustInfoName As Variant 'Name of field (Revision)

' Check the documentation in Visual Basic or Visual C++ for printer definitions
    Const vbPRORPortrait = 1
    Const vbPRORLandscape = 2
    ' Defined in swconst.bas
    Const swPrintPaperSize = 0
    Const swPrintOrientation = 1

Option Explicit

Sub CreatePDF()

    Set swApp = Application.SldWorks
    Set Part = swApp.ActiveDoc
    Set swModel = swApp.ActiveDoc
    ' These definitions are consistent with type names defined in swconst.bas
    Const swDocPART = 1
    Const swDocASSEMBLY = 2
    Const swDocDRAWING = 3
''' BEGIN CREATE PDF '''
'' Define FILE PATH ''
    Dim FPath As String
    'FPath = "Current_dir"
    FPath = (CurDir + "\")
    Dim nErrors As Long
    Dim nWarnings As Long
    Dim sStartFileName As String 'Starting file name
       
'************************************************************************
    ' Get File name of open drawing
    ' strip off SolidWorks file extension (slddrw)
    ' and add DXF extension (dxf)
    'sFileName = swModel.GetTitle 'Not Using this feature
    ' Now use this... Get File name from File>Properties Custom tab, PartNo field.
    FNConfigName = ""
    FNCustInfoName = "PartNo"
    sFileName = swModel.CustomInfo2(FNConfigName, FNCustInfoName)
'************************************************************************
'Capture path name for file
    sStartFileName = swModel.GetPathName()

' Get Revision Number
    RevConfigName = ""
    RevCustInfoName = "Revision"
    RevNum = swModel.CustomInfo2(RevConfigName, RevCustInfoName)
    'Left(string, length)
    RevNum = Left(RevNum, 2) 'Only get the first 2 characters in this field
If swModel.GetType = swDocDRAWING Then
   If MsgBox("Are you sure you would like to create " + _
    vbCrLf + FPath + sFileName + "-" + RevNum & ".PDF ? ", vbYesNo + vbQuestion, "Create PDF?") = vbYes Then sFileName = sFileName + "-" + RevNum
       
        'Plot to FILE name
        pltName = FPath + sFileName + ".pdf"
        ' Save to PDF
        Part.SaveAs4 pltName, 0, swSaveAsOptions_Silent, nErrors, nWarnings

        Else
        Exit Sub

End If


End Sub

Outcomes