Export IDW to PDF (With Rename Option)

Export IDW to PDF (With Rename Option)

Chirpyboy2060647
Advocate Advocate
520 Views
3 Replies
Message 1 of 4

Export IDW to PDF (With Rename Option)

Chirpyboy2060647
Advocate
Advocate

Hi all im back with another coding issue. The issue we have with our current macro for exporting pdfs is that I have to constantly go find the folder i want to save it at.

 

Current:

 

This is our current macro that goes with printing options. This always picks the last folder a file was saved too. Id like to fix this to pick the current idw's location/name so i can cut the time searching for the folder or at times forget i have to change it. Any suggestions? The one i found will write to the folders location/name great but i need the option to save it else where or name it something else when i get revision numbers. Any one able to help?

 

Private Sub UserForm_Initialize()

Set oDoc = ThisApplication.ActiveDocument
Set oPrint = oDoc.PrintManager
Set oProperties = oDoc.PropertySets.Item(4)

If oDoc.PropertySets.Item(2).Item("Category").Expression = "2" Then
Set oRevisionTable = oDoc.ActiveSheet.RevisionTables.Item(1)
Else
cmdShop.Enabled = False
cmdShopEng.Enabled = False
End If

 

If chbPDF.value = True Then
oPrint.Printer = "CutePDF Writer"
oPrint.ScaleMode = kPrintBestFitScale
oPrint.PaperSize = kPaperSize11x17
oPrint.NumberOfCopies = 1
oPrint.SubmitPrint
End If

 

I was thinking of trying to add something like

 

printsfileLocation=ThisDoc.Path

 But i dont wanna mess with it too much yet without something concrete or better to go off of.

 

Edit:

 

 

Or if there is a way to add the option to rename the file or for it to add the tag "_RevNumber"

 

 

Sub Main
printsfileLocation=ThisDoc.Path
oMemberName=ThisDoc.FileName(False) 'without extension
exportPDF(printsfileLocation, oMemberName, ThisApplication.activedocument)
End Sub
Sub exportPDF(oPath As String, oFileName As String, oDocument As Document)
Try
oPDFAddIn = ThisApplication.ApplicationAddIns.ItemById _
("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
Dim oDrawing as DrawingDocument = oDocument
Dim sheetCount As Integer = oDrawing.Sheets.Count
If oPDFAddIn.HasSaveCopyAsOptions(oDataMedium, oContext, oOptions) Then
oOptions.Value("All_Color_AS_Black") = 1
oOptions.Value("Remove_Line_Weights") = 1
oOptions.Value("Vector_Resolution") = 400
oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintSheetRange
oOptions.Value("Custom_Begin_Sheet") = 1
oOptions.Value("Custom_End_Sheet") = sheetcount
End If
oDataMedium.FileName = oPath & "\" & oFileName & ".pdf" ' check carefully this line
oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
Catch
End Try
End Sub

 

0 Likes
Accepted solutions (1)
521 Views
3 Replies
Replies (3)
Message 2 of 4

Chirpyboy2060647
Advocate
Advocate
Please Delete or Void I figured it out
0 Likes
Message 3 of 4

pball
Mentor
Mentor
Just a word of advice. If you figure something out yourself go ahead and post what you found. It can only help people in the future if they find your thread.
Check out my style edits for the Autodesk forums
pball's Autodesk Forum Style
0 Likes
Message 4 of 4

Chirpyboy2060647
Advocate
Advocate
Accepted solution

Ha yeah was thinking that on my home after work. Well heres my work to print a pdf to the idw file location. It also adds the Rev number to the file if Rev is greater then 0

 

 

Sub Main
printsfileLocation=ThisDoc.Path
oMemberName=ThisDoc.FileName(False) 'without extension
exportPDF(printsfileLocation, oMemberName, ThisApplication.activedocument)
End Sub
Sub exportPDF(oPath As String, oFileName As String, oDocument As Document)
Try
oPDFAddIn = ThisApplication.ApplicationAddIns.ItemById _
("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
Dim oDrawing as DrawingDocument = oDocument
Dim sheetCount As Integer = oDrawing.Sheets.Count
If oPDFAddIn.HasSaveCopyAsOptions(oDataMedium, oContext, oOptions) Then
oOptions.Value("All_Color_AS_Black") = 1
oOptions.Value("Remove_Line_Weights") = 1
oOptions.Value("Vector_Resolution") = 400
oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintSheetRange
oOptions.Value("Custom_Begin_Sheet") = 1
oOptions.Value("Custom_End_Sheet") = sheetcount
End If

If iProperties.Value("Project", "Revision Number") = 0 Then
oDataMedium.FileName = oPath & "\" & oFileName & ".pdf"
oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
End If

If iProperties.Value("Project", "Revision Number") > 0 Then
oDataMedium.FileName = oPath & "\" & oFileName & " R_" & iProperties.Value("Project", "Revision Number") & ".pdf" ' check carefully this line
oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
End If
Catch
End Try

End Sub

 

0 Likes