- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am working on a macro for automatically creating a PDF during a drawing save. For now, since I don't really know that much about programming, I mostly find existing code examples and modify / combine them into what I need. This one was created mostly using some of the examples from the API help, along with some tweaking based on code I found online.
The macro is intended to reside in the document, since the file path for the automatic PDF will need to change for each project, and in some cases by individual drawing. The actual path will replace the "Temp" path that I have left in the code from the sample for testing purposes. This will require some tweaking of the macro on individual drawings, but I have no problem with doing that to set things up if the PDF creation after that becomes automatic. The point is to automatically have a copy of the latest revision of the drawing as PDF in a "Draft" folder, for others to view. We currently are supposed to do this manually, and Iit is often forgotten, so PDF's are missing when needed.
My current issue is this:
I would like the PDF to be automatically named to our standard convention, which is "Drawing Number (Rev ??).pdf". The drawing number is usually the same as the filename, so I am using the document display name to get that part, which I found in an example somewhere on these forums. I'm having some trouble figuring out how to get the revision to fill in.
What would I need to add to my code to get the revision into the PDF file name? My class module code is below.
Option Explicit
Private WithEvents oApplicationEvents As ApplicationEvents
Private Sub Class_Initialize()
Set oApplicationEvents = ThisApplication.ApplicationEvents
End Sub
Private Sub Class_Terminate()
Set oApplicationEvents = Nothing
End Sub
Private Sub oApplicationEvents_OnSaveDocument(ByVal DocumentObject As Document, ByVal BeforeOrAfter As EventTimingEnum, ByVal Context As NameValueMap, HandlingCode As HandlingCodeEnum)
If (BeforeOrAfter = kBefore) Then
MsgBox ("about to save " & DocumentObject.FullFileName)
'Get the PDF translator Add-In.
Dim PDFAddIn As TranslatorAddIn
Set PDFAddIn = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
'Set a reference to the active document (the document to be published).
Dim oDocument As Document
Set oDocument = ThisApplication.ActiveDocument
Dim oContext As TranslationContext
Set oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = kFileBrowseIOMechanism
' Create a NameValueMap object
Dim oOptions As NameValueMap
Set oOptions = ThisApplication.TransientObjects.CreateNameValueMap
' Create a DataMedium object
Dim oDataMedium As DataMedium
Set oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
' Check whether the translator has 'SaveCopyAs' options
If PDFAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then
' Options for drawings...
oOptions.Value("All_Color_AS_Black") = 0
'oOptions.Value("Remove_Line_Weights") = 0
'oOptions.Value("Vector_Resolution") = 400
'oOptions.Value("Sheet_Range") = kPrintAllSheets
'oOptions.Value("Custom_Begin_Sheet") = 2
'oOptions.Value("Custom_End_Sheet") = 4
End If
'Set the destination file name
oDataMedium.FileName = "c:\temp\" & Left(DocumentObject.DisplayName, Len(DocumentObject.DisplayName) - 4) & " (REV " & ".pdf"
'Publish document.
Call PDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
Else
MsgBox (DocumentObject.FullFileName & " has been saved")
End If
End Sub
Any help would be appreciated.
Solved! Go to Solution.