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.