Hello All,
I am quite new to ilogic and am not sure where to go with this issue.
I have created ani-Logic rule based on Curtis Waguespack's Export to PDF on save code. My problem is that on some occasions I want to overwrite an existing PDF or DWFx (without creating a new revision) which has been created with this rule but when I run the rule, it appears to be creating a new file but the old file stiil exists and does not get overwritten.
Code below.
Regards
'------start of iLogic-------
oPath = ThisDoc.Path oFileName = ThisDoc.FileName(False) 'without extensionoRevNum = iProperties.Value("Project", "Revision Number") oDescrip = iProperties.Value("Project", "Description") 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") = 1 oOptions.Value("Remove_Line_Weights") = 1 oOptions.Value("Vector_Resolution") = 400 oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets 'oOptions.Value("Custom_Begin_Sheet") = 2'oOptions.Value("Custom_End_Sheet") = 4
End If 'Gets the Workspace PathWorkspacePath= ThisDoc.WorkspacePath() 'Gets the Length of the WorkspacePath StringWorkspacePathLength = Len(WorkspacePath) 'Gets just the Path of the filePathOnly = ThisDoc.Path 'Removes the Workspace Path from FullPathDirectoryPath = Strings.Right(PathOnly, PathOnly.Length-WorkspacePathLength) 'Sets the Directory that the PDF should be saved inPDFPath = "S:\Shared Documents\" & DirectoryPath 'Checks to see if that directory exists, if not, it is createdIf(Not System.IO.Directory.Exists(PDFPath)) Then System.IO.Directory.CreateDirectory(PDFPath) End If question = MessageBox.Show("Do you want print PDF drawing?", "iLogic Question",MessageBoxButtons.YesNo,MessageBoxIcon.Question) 'set condition based on answer If question = vbYes Then 'Set the PDF target file name ThisDoc.Document.SaveAs(PDFPath & "\" & ThisDoc.FileName(False) & _ " Rev" & oRevNum & " - " & oDescrip & ".pdf" , True) Else If question = vbNo Then End If question = MessageBox.Show("Do you want print DWFx drawing?", "iLogic Question",MessageBoxButtons.YesNo,MessageBoxIcon.Question) 'set condition based on answer If question = vbYes Then 'Set the DWFx target file name ThisDoc.Document.SaveAs(PDFPath & "\" & ThisDoc.FileName(False) & _ " Rev" & oRevNum & " - " & oDescrip & ".dwfx" , True) Else If question = vbNo Then End If
Solved! Go to Solution.
Solved by adam.nagy. Go to Solution.
Hi,
Inside iLogic you can use .NET Framework functionality including the ones inside System.IO namespace.
So at the beginning of your code you could check if the file already exists, and if so delete it or rename it before runing the saveas part.
If System.IO.File.Exists("C:\myfile.txt") Then MsgBox("Exists") Else MsgBox("Does not exist") End If
Cheers,
I try to rename a existant file with System.IO.File.Move(OLDFILE, NEWFILE)
but my rule dont work???
DOSSIER = ThisDoc.Path
POSITION1 = InStrRev(DOSSIER, "\")
POSITION2 = Right(DOSSIER, Len(DOSSIER) - POSITION1)
'get PDF target folder path
oFolder = "I:\DOCUMENTS\ARTICLES\" & POSITION2 & "\"
'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 System.IO.File.Exists(oFolder & oFileName & ".PDF") Then
question = MessageBox.Show("LE PDF EXISTE, EST-CE QUE TU VEUX CRÉER UN OLD VERSION? SI TU RÉPOND NON L'EXISTANT SERA EFFACER", "PDF???", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1)
MultiValue.SetValueOptions(True)
End If
If question = vbYes Then
OLDFILE = oFolder & POSITION2 & "\" & oFileName & ".PDF"
NEWFILE = oFolder & POSITION2 & "\" & oFileName & Now & ".PDF"
System.IO.File.Move(OLDFILE, NEWFILE)
Else If question = vbNo Then
Kill (oFolder & oFileName & ".PDF")
End If
Thanks for your help 🙂