You can modify default behavior of Inventor SaveFileDialog, but it can have some side effects. You can hook to FileUIEvents.OnFileSaveAsDialog event. In this event you have two possibilities.
- Set arguments of the event FileName to full file name and HandlingCode to Handled. In this case the dialog is not displayed and your file name is used and the document is saved. But you are responsible for full file name generation and user has no chance to change them.
- Obtain the SaveFileDialog object from Context argument and pass full file name to it. In this case the dialog is displayed, user can change file name and location, but when you pass correct full file name, the user can just click OK. See the sample code
- Another approaches like FileUIEvents.OnPopulateFileMetadata, PostPrivateEvent, ApplicationEvents.OnSaveDocument etc. can be used, but it is not useful in my opinion.
Side effects of all approaches mentioned above are
- It is hard to determine when you want to handle the SaveFileDialog. Because the event doesn't provide information about saved document.
- It can be in conflict with another tool which can modify the file name like Vault Pro, DataStandards, etc.
For this task is very useful to use EventWatcher from SDK, which can help you to understand events order and to specify the behavior of your tool.
iLogic code sample for manipulation with FileDialog during OnFileSaveAsDialog event. It uses SharedVariable to store and restart event handler. It is just for testing purposes. In real implementation use your own add-in instead of iLogic.
Sub Main()
Dim handlerName As String = "OnFileSaveAsDialogHandler"
If SharedVariable.Exists(handlerName) Then
Dim oldHandler = SharedVariable.Value(handlerName)
oldHandler.Deactivate()
End If
Dim newHandler = New OnFileSaveAsDialogHandler(ThisApplication)
SharedVariable.Value(handlerName) = newHandler
newHandler.Activate()
End Sub
Class OnFileSaveAsDialogHandler
Public Property ThisApplication As Inventor.Application
Dim _fileUiEvents As FileUIEvents
Public Sub New(thisApplication As Inventor.Application)
Me.ThisApplication = thisApplication
End Sub
Public Sub Activate()
_fileUiEvents = ThisApplication.FileUIEvents
AddHandler _fileUiEvents.OnFileSaveAsDialog, AddressOf FileUIEvents_OnFileSaveAsDialog
End Sub
Public Sub Deactivate()
RemoveHandler _fileUiEvents.OnFileSaveAsDialog, AddressOf FileUIEvents_OnFileSaveAsDialog
_fileUiEvents = Nothing
End Sub
Private Sub FileUIEvents_OnFileSaveAsDialog(ByRef fileTypes As String(),
saveCopyAs As Boolean,
parentHwnd As Integer,
ByRef fileName As String,
context As NameValueMap,
ByRef handlingCode As HandlingCodeEnum)
handlingCode = HandlingCodeEnum.kEventNotHandled
Dim fileDialog as Inventor.FileDialog = context.Value("FileDialog")
fileDialog.FileName = "C:\Temp\" & fileDialog.FileName
End Sub
End Class