Issue
How to override the Inventor native "File Open" and "File Save As" dialog boxes?
Solution
It is possible to override the Inventor's native FileOpen and FileSave dialog boxes. This would normally be done by overriding the FileUIEvents_OnFileOpenDialog or FileUIEvents_OnFileSaveAsDialog method respectively. When you override the event methods, you could choose to implement your own functionality as part of the event methods, thus allowing you to, for example, display your own custom dialog boxes. One of the options could be to use Microsoft's common "File Open" or "Save As" dialogs.
The following shows the VB code when the "FileUIEvents_OnFileOpenDialog" event has been overridden to display a custom file open dialog box:
Private Sub m_FileUIEvents_OnFileOpenDialog_1( _
ByRef FileTypes() As String, _
ByVal ParentHWND As Integer, _
ByRef FileName As String, _
ByVal Context As Inventor.NameValueMap, _
ByRef HandlingCode As Inventor.HandlingCodeEnum)
' USE YOUR OWN CUSTOM FILE DIALOG
' e.g. Microsoft's FileOpenDialog
' Display the dialog for the user to enter a filename.
Dim m_FileOpenForm As System.Windows.Forms.OpenFileDialog _
= New System.Windows.Forms.OpenFileDialog
With m_FileOpenForm
'Set the initial Directory
.InitialDirectory = "C:\Program Files\Autodesk"
.Title = "File Open"
.Filter = "Part File (*.ipt)|*.ipt" _
& "|Assembly File (*.iam)|*.iam" _
& "|Presentation File (*.ipn)|*.ipn" _
& "|Drawing File (*.idw)|*.idw" _
& "|Design element File (*.ide)|*.ide"
.FilterIndex = 1 ' *.ipt files
.Multiselect = False
.ShowDialog()
End With
If m_FileOpenForm.FileNames.Length = 0 Then
HandlingCode = HandlingCodeEnum.kEventCanceled
Else
FileName = m_FileOpenForm.FileNames(0)
HandlingCode = HandlingCodeEnum.kEventHandled
End If
m_FileOpenForm = Nothing
End Sub
Another option would be to customize the native Inventor dialog boxes themselves. You may set the default directory, default file name, file filters, enable multiselection mode and 'Options' button and also may suppress resolution warnings. Here is C# sample of native Inventor FileDialog customization.
private void btn_OpenFile_Click(object sender, EventArgs e)
{
// Create a new FileDialog object.
Inventor.FileDialog oFileDlg;
oApp.CreateFileDialog(out(oFileDlg));
// Define the filter to select part
// and assembly files or any file.
oFileDlg.Filter =
"Inventor Files (*.iam;*.ipt)|*.iam;*.ipt|All Files )|*.*";
// Define the part and assembly files filter
// to be the default filter.
oFileDlg.FilterIndex = 1;
// Set the title for the dialog.
oFileDlg.DialogTitle = "Open File Test";
// Set the initial directory that
// will be displayed in the dialog.
oFileDlg.InitialDirectory = @"C:\Program Files\Autodesk";
// Set the flag so an error will not be raised
// if the user clicks the Cancel button.
oFileDlg.CancelError = false;
// Show the open dialog. The same procedure
// is also used for the Save dialog.
// The commented code can be used for the Save dialog.
oFileDlg.ShowOpen();
// oFileDlg.ShowSave();
System.Windows.Forms.MessageBox.Show(
"File \n" + oFileDlg.FileName + "\nwas selected.",
"Selected file");
}