Message 1 of 9
If STEP file exists, prompt message if user wants to overwrite file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello everyone and I hope your Friday is going well!
I'm automating STEP file creation upon saving the native Inventor file. I would like for the code to detect if the STEP file already exists, and then prompt the user with a message box and ask them if they want to overwrite the STEP file or not.
I've tried adding the System IO check on the frontend of the code to try and catch if it exists to at least prompt a message box so I know that part of the code is working, but I can't seem to get a message box to prompt. What am I missing to #1 check if t file already exists and #2 create a message box asking them if they want to overwrite the file or not?
If System.IO.File.Exists(ThisDoc.Path & "\" & oStepFileName & ".stp") Then MessageBox.Show("The STEP file already exists in this location.") Else trigger = iTrigger0 ' Get the STEP translator Add-In. Dim oSTEPTranslator As TranslatorAddIn oSTEPTranslator = ThisApplication.ApplicationAddIns.ItemById("{90AF7F40-0C01-11D5-8E83-0010B541CD80}") Dim oContext As TranslationContext oContext = ThisApplication.TransientObjects.CreateTranslationContext Dim oOptions As NameValueMap oOptions = ThisApplication.TransientObjects.CreateNameValueMap ' Get Part Number Dim sPN As String = iProperties.Value("Project", "Part Number") If sPN.StartsWith("U") Then oStepFileName = iProperties.Value("Custom", "FS Part Number") Else If sPN.StartsWith("PS") Then oStepFileName = iProperties.Value("Project", "Part Number") End If If oSTEPTranslator.HasSaveCopyAsOptions(ThisApplication.ActiveDocument, oContext, oOptions) Then ' Set application protocol. ' 2 = AP 203 - Configuration Controlled Design ' 3 = AP 214 - Automotive Design oOptions.Value("ApplicationProtocolType") = 3 ' Other options... 'oOptions.Value("Author") = "" 'oOptions.Value("Authorization") = "" 'oOptions.Value("Description") = "" 'oOptions.Value("Organization") = "" oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism Dim oData As DataMedium oData = ThisApplication.TransientObjects.CreateDataMedium oData.FileName = ThisDoc.Path & "\" & oStepFileName & ".stp" oSTEPTranslator.SaveCopyAs(ThisApplication.ActiveDocument, oContext, oOptions, oData) End If End If
Regards,
Kenny
If this post solved your issue please mark "Accept as Solution". It helps everyone...really!
Kenny
If this post solved your issue please mark "Accept as Solution". It helps everyone...really!