Save as pdf but i want also the rule to delete older pdf files

Save as pdf but i want also the rule to delete older pdf files

Charlies_3D_T
Advocate Advocate
1,139 Views
7 Replies
Message 1 of 8

Save as pdf but i want also the rule to delete older pdf files

Charlies_3D_T
Advocate
Advocate

Hello,

 

I'm working on a code that creates a pdf file from a drawing but in that name has to be the part number and description. If i change the number or the description the rul has to delete the older pdf first and save a new one with the new name. 

 

ThisDrawing.Document.SaveAs(oFolderParts & "\" & PartNumber & "_" & PartDescription & "_REV_" & iProperties.Value("Project","Revision Number") & ".pdf", True)

Any one has done this before?  

0 Likes
1,140 Views
7 Replies
Replies (7)
Message 2 of 8

Jesper_S
Collaborator
Collaborator

Hi.

 

I have been using this iLogic. 

It doesn't delete the PDF files, it moves them to a folder called Obsolete.

Imports System.Windows.Forms	
' Get current location of this file
'Dim ExportPath As String = ThisDoc.Path
Dim ExportPath As String = "G:\Order kund\"
'query user
question = MessageBox.Show("Is a .PDF Export Required?", iProperties.Value("Project", "Part Number"),MessageBoxButtons.YesNo,MessageBoxIcon.Question)
'set condition based on answer
If question = vbYes Then

' Define folder browse dialog
Dim Dialog = New FolderBrowserDialog()

' Set options for folder browser dialog
Dialog.SelectedPath = ExportPath
Dialog.ShowNewFolderButton = True
Dialog.Description = ("Choose Folder for Export Dwg ") & iProperties.Value("Project", "Part Number")

' Show dialog box
If DialogResult.OK = Dialog.ShowDialog() Then
	' User clicked 'ok' on dialog box - capture the export path
	ExportPath = Dialog.SelectedPath '& "\"
	
Else
	' User clicked 'cancel' on dialog box - exit
	Return
End If
'------PDF Setup-------
oPath = ExportPath
oFileName = iProperties.Value("Project", "Part Number")
oRevNum = iProperties.Value("Project", "Revision Number")
oPDFAddIn = ThisApplication.ApplicationAddIns.ItemById _
("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
oDocument = ThisApplication.ActiveDocument
oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
oDataMedium = ThisApplication.TransientObjects.CreateDataMedium

If oPDFAddIn.HasSaveCopyAsOptions(oDataMedium, oContext, oOptions) Then
oOptions.Value("All_Color_AS_Black") = 0
oOptions.Value("Remove_Line_Weights") = 0
oOptions.Value("Vector_Resolution") = 400
oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets
oOptions.Value("Custom_Begin_Sheet") = 1
oOptions.Value("Custom_End_Sheet") = 10
End If

'get PDF target folder path
oFolder = oPath '& "\PDF"

'Check for the PDF folder and create it if it does not exist
If Not System.IO.Directory.Exists(oFolder) Then
    System.IO.Directory.CreateDirectory(oFolder)
End If

If iProperties.Value("Project", "Revision Number") = Nothing Then
 'Set the PDF target file name
oDataMedium.FileName = oFolder & "\" & oFileName & ".pdf"
Else
'Set the destination file name
oDataMedium.FileName = oFolder & "\" & oFileName & _
" Rev " & oRevNum & ".pdf"
End If
Else 
Return
End If

On Error Goto handlePDFLock

'Publish document
oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)

If oRevNum >= "1" Then
Dim EarlyRev As String = Chr(Asc(oRevNum) - 1)
Dim FileCurrent As String = oPath & PDF_Folder & "\" & oFileName & " Rev " & EarlyRev & ".pdf"
Dim FileObs As String = oPath & PDF_Folder & "\OBSOLETE\" & oFileName & " Rev " & EarlyRev & ".pdf"
Dim oObs As String = oPath & "\OBSOLETE\"
If Not System.IO.Directory.Exists(oObs) Then
   System.IO.Directory.CreateDirectory(oObs)
End If
If System.IO.File.Exists(FileCurrent) = True Then
System.IO.File.Move(FileCurrent, FileObs)
Else
'If System.IO.File.Exists(Fileobs) = False Then
'MessageBox.Show("Revision " & EarlyRev & " is missing!", "iLogic")
'End If
End If
End If

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

Exit Sub

handlePDFLock:
MessageBox.Show("PDF not created, most likely someone else has it open.", "No PDF for you " & ThisApplication.GeneralOptions.UserName & "!")
Resume Next

'Show message box
MessageBox.Show("Drawing saved and PDF Exported to LAST EDITED document folder/PDF", "Save I-logic")
'------end of iLogic-------

You can use it as a base and perhaps change some of the code.

Perhaps change this

If System.IO.File.Exists(FileCurrent) = True Then
System.IO.File.Move(FileCurrent, FileObs)

to this

If System.IO.File.Exists(FileCurrent) = True Then
System.IO.File.Delete(FileCurrent, FileObs)

Dont know if it will work buts it's an idea.


//Jesper

Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.
0 Likes
Message 3 of 8

Charlies_3D_T
Advocate
Advocate

@Jesper_S 

 

Thank you! But my problem is that my name could change if i change the number. So in one way or an other i need to save the old name and first search for it and delete it if it's not the same as a new name. 

 

That's my problem. 

0 Likes
Message 4 of 8

bradeneuropeArthur
Mentor
Mentor

maybe this way:

 

If System.IO.File.Exists(oFolderParts & "\" & PartNumber & "_" & PartDescription & "_REV_" & iProperties.Value("Project","Revision Number") & ".pdf") = True Then
System.IO.File.Delete(oFolderParts & "\" & PartNumber & "_" & PartDescription & "_REV_" & iProperties.Value("Project","Revision Number") & ".pdf", FileObs)

Regards,

Autodesk Software: Inventor Professional 2018 | Vault Professional 2018 | Autocad Mechanical 2018
Programming Skills: Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Dimension Component! | Partlist Export! | Derive I-properties! | Vault Prompts Via API! | Vault Handbook/Manual!
Drawing Toggle Sheets! | Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved ! 

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 5 of 8

tom.quinzi
Observer
Observer

Hi,

 

But excuse my ignorance, how do I get Vault to run this rule?

 

Thanks

 

Tom

0 Likes
Message 6 of 8

bradeneuropeArthur
Mentor
Mentor

Hi,

 

You need to create a "Custom Job " for Vault-Extension for this.

Than you need to add this job as a Custom job to any Lifecycle change event.

If correctly done the jib will run and do its tasks.

 

Seems to be simple but it is a little more complex than these three lines....

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 7 of 8

tom.quinzi
Observer
Observer

Ok thanks for your reply.

 

Do I need coolOrange to run these custom scripts?

 

Thanks,

 

Tom

0 Likes
Message 8 of 8

bradeneuropeArthur
Mentor
Mentor

No, you don't need that.

 

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes