FileUI Events

The FileInsertDialog event notifies the client whenever the user executes a command that selects a document to be inserted into another document, for example Place Component in an assembly, Derived Component in a part or Base View in a drawing. The event fires at the point where Inventor would display the standard Open dialog.

EventNames:

  • FileInsertDialog_Pre

Parameters

Type

Name

Description

ResultParameters

result

Object used to supply the result of the operation. See below.

Document

document

The object the file will be inserted into. For example, if the Place Component is invoked, this will be the assembly the component is being inserted into

Result properties:

Type

Name

Description

String

FileName

The file name to use.

String

DirectoryPath

The directory where the file that should be inserted is in.

String

FullFileName

The full file name of the file that will be used. Can be used to check that the set file name is correct.

Remarks:

Three common commands are the Place Component command in assembly, the Derived Component command in part, and the Base View command in drawing.

By using this event and setting a fileName and directoryPath to the result variable, the user can replace the default Inventor behavior, normally used to replace the Inventor dialog with their own dialog.

To change the default behavior of Inventor you need to set both the FileName and DirectoryPath to the result variable, if none are set, the behavior will stay the same.

This event can be aborted by throwing an exception inside the action.
Throwing an OperationCanceledException aborts the operation without any message.
Throwing any other exception aborts the operation and displays the thrown exception in an Error Message Box.

Examples:

FileInsertDialog_Pre:

Register-InventorEvent -EventName FileInsertDialog_Pre -Action 'PreFileInsertDialog'

function PreFileInsertDialog($result, $document) {
	#Write event code here
	$result.FileName = "12345.ipt"
	$result.DirectoryPath = "C:\Vault"
	$result.FullFileName # C:\Vault\12345.ipt
}

The FileInsertNewDialog event notifies the client whenever the user executes the Create Component command within an assembly. The event fires immediately after the command is executed, but before Inventor displays the standard Create In-Place Component dialog.

EventNames:

  • FileInsertNewDialog_Pre

Parameters

Type

Name

Description

String

templateDirectory

The default template directory as defined in the File tab of the Application Options dialog

ResultParameters

result

Object used to supply the result of the operation. See below.

Document

document

The document object the new component will be created within

Result properties:

Type

Name

Description

String

FileName

The file name to use.

String

DirectoryPath

The directory where the file that should be inserted is in.

String

FullFileName

The full file name of the file, can be used to check that the fileName set is correct.

String

TemplateFileName

The filename of the file to use as the template when creating the new component.

String

TemplateDirectoryPath

The directory of the file to use as the template when creating the new component.

String

TemplateFullFileName

The full file name of the template file, can be used to check that the fileName set is correct

Remarks:

To change the default behavior of Inventor you need to set both the FileName and DirectoryPath to the result variable, if none are set, the behavior will stay the same.
If the TemplateFileName is not set the default template will be used. To set the Template file name you will need to set both the TemplateFileName and TemplateDirectoryPath properties.

This event can be aborted by throwing an exception inside the action.
Throwing an OperationCanceledException aborts the operation without any message.
Throwing any other exception aborts the operation and displays the thrown exception in an Error Message Box.

Examples:

FileInsertNewDialog_Pre:

Register-InventorEvent -EventName FileInsertNewDialog_Pre -Action 'PreFileInsertNewDialog'

function PreFileInsertNewDialog($templateDirectory, $result, $document) {
	#Write event code here
	$result.FileName = "12345.ipt"
	$result.DirectoryPath = "C:\Vault"
	$result.FullFileName #Returns the FullFileName e.g "C:\Vault\12345.ipt", cannot be set.
	$result.TemplateFileName = "template.ipt"
	$result.TemplateDirectoryPath = "C:\Templates"
	$result.TemplateFullFileName #Returns the TemplateFullFileName e.g "C:\Templates\template.ipt", cannot be set.
}

The FileNew event fires before a new file is created from a standard template (File New). This is for example the case when the document type is selected from the pop-up list next to the New command; the Create New File dialog is bypassed then, so [FileNewDialog](<</code_reference/objects/inventor_event_mappings/fileui_events/filenewdialog>) is not triggered.

EventNames:

  • FileNew_Pre

Parameters

Type

Name

Description

DocumentTypeEnum

documentType

DocumentTypeEnum indicating the document type

Remarks:

This event can be aborted by throwing an exception inside the action.
Throwing an OperationCanceledException aborts the operation without any message.
Throwing any other exception aborts the operation and displays the thrown exception in an Error Message Box.

Examples:

FileNew_Pre:

Register-InventorEvent -EventName FileNew_Pre -Action 'PreFileNew'

function PreFileNew($documentType) {
	#Write event code here
}

The FileNewDialog event notifies the client when the user executes the New or Create Drawing View command to create a new file, at the point where Inventor would display the Create New File dialog to select a template.
The event is not triggered if the dialog is bypassed, for example when the document type is selected from the pop-up list next to the New command (see [FileNew](<</code_reference/objects/inventor_event_mappings/fileui_events/filenew>)).

EventNames:

  • FileNewDialog_Pre

Parameters

Type

Name

Description

String

templateDirectory

The default template directory as defined in the File tab of the Application Options dialog.

ResultParameters

result

Object used to supply the result of the operation. See below.

Result properties:

Type

Name

Description

String

TemplateFileName

The filename of the file to use as the template when creating the new file.

String

TemplateDirectoryPath

The directory of the file to use as the template when creating the new file.

String

TemplateFullFileName

The full file name of the template file, can be used to check that the fileName set is correct

Remarks:

If the end-user uses the pop-up command list next to the New command to select an assembly, part, presentation, or drawing document, the Create New File dialog is bypassed and this notification is not sent in this case.

This event can be aborted by throwing an exception inside the action.
Throwing an OperationCanceledException aborts the operation without any message.
Throwing any other exception aborts the operation and displays the thrown exception in an Error Message Box.

Examples:

FileNewDialog_Pre:

Register-InventorEvent -EventName FileNewDialog_Pre -Action 'PreFileNewDialog'

function PreFileNewDialog($templateDirectory, $result) {
	#Write event code here
	$result.TemplateFileName = "template.ipt"
	$result.TemplateDirectoryPath = "C:\Templates"
	$result.TemplateFullFileName #Returns the TemplateFullFileName e.g "C:\Templates\template.ipt", cannot be set.
}

The FileOpenDialog event notifies the client when the user executes the Open command to open an existing file, at the point where Inventor would display the Open dialog.
The event is not triggered if the Open dialog is bypassed, for example when a file is opened from the most recently used list (see [FileOpenFromMRU](<</code_reference/objects/inventor_event_mappings/fileui_events/fileopenfrommru>)).

EventNames:

  • FileOpenDialog_Pre

Parameters

Type

Name

Description

ResultParameters

result

Object used to supply the result of the operation. See below.

Result properties:

Type

Name

Description

String

FileName

The file name to use.

String

DirectoryPath

The directory where the file that should be opened is in.

String

FullFileName

The full file name of the file that will be used. Can be used to check that the set file name is correct.

Remarks:

By using this event and setting a fileName and directoryPath to the result variable, the user can replace the default Inventor behavior, normally used to replace the Inventor dialog with their own dialog.

This event can be aborted by throwing an exception inside the action.
Throwing an OperationCanceledException aborts the operation without any message.
Throwing any other exception aborts the operation and displays the thrown exception in an Error Message Box.

Examples:

FileOpenDialog_Pre:

Register-InventorEvent -EventName FileOpenDialog_Pre -Action 'PreFileOpenDialog'

function PreFileOpenDialog($result) {
	#Write event code here
	$result.FileName = "12345.ipt"
	$result.DirectoryPath = "C:\Vault"
	$result.FullFileName # C:\Vault\12345.ipt
}

The FileOpenFromMRU event notifies the client when the user selects a file from the most recently used (MRU) list to open it. The Open dialog is bypassed in this case, so [FileOpenDialog](<</code_reference/objects/inventor_event_mappings/fileui_events/fileopendialog>) is not triggered.

EventNames:

  • FileOpenFromMRU_Pre

Remarks:

This event can be aborted by throwing an exception inside the action.
Throwing an OperationCanceledException aborts the operation without any message.
Throwing any other exception aborts the operation and displays the thrown exception in an Error Message Box.

Examples:

FileOpenFromMRU_Pre:

Register-InventorEvent -EventName FileOpenFromMRU_Pre -Action 'PreFileOpenFromMRU'

function PreFileOpenFromMRU() {
	#Write event code here
}

The FileSaveAsDialog event runs before Inventor displays a Save dialog, for example when saving a new document for the first time or using Save Copy As or Export commands.
It allows you to easily replace the standard Inventor Save dialog with your own dialog or workflow.

EventNames:

  • FileSaveAsDialog_Pre

Parameters

Type

Name

Description

Document

document

The document to be saved

bool

isSaveCopyAs

$true for Save Copy As or Export operations; otherwise $false.

ResultParameters

result

Used to specify the resulting file name and path for the save operation. See below.

Result properties:

Type

Name

Description

String

FileName

The file name to use.

String

DirectoryPath

The directory to save the file in.

String

FullFileName

The complete save location of the document.

Remarks:

The default Inventor save behavior can be easily replaced by setting properties of $result:

  • FullFileName: Set this to specify the full path and file name Inventor should use when saving the $document.
    By default, it contains Inventor’s default save location and file name (same as $document.FullFileName). This is useful for displaying the default values in a custom save dialog.

  • FileName: Alternatively, you can modify only the file name while keeping Inventor’s default save location.

  • DirectoryPath: Initially contains Inventor’s default save location. Set this to only specify a custom directory while keeping the default file name.

To cancel the entire save operation without an error message, e.g. when the user cancels a custom dialog, the event supports throwing an OperationCanceledException.
See Register-InventorEvent for more details on other unhandled exceptions.

Vault Data Standard (VDS) - SaveAs dialog

When Vault Data Standard (VDS) is enabled, we do not recommend using this event together with the VDS Save As dialog because it may lead to unexpected results.

Known issues:

  1. When saving a new document for the first time after starting Inventor, only the VDS dialog appears; FileSaveAsDialog_Pre does not run. For subsequent saves of new documents, it runs before the VDS dialog as expected.

  2. After cancelling the save operation in FileSaveAsDialog_Pre, the VDS dialog still appears.

Examples:

Replace & customize the standard Vault Numbering Generation for document names:

Register-InventorEvent -EventName FileSaveAsDialog_Pre -Action 'PreSaveDialog_UseVaultNumberingGenerator' #<- invoked before the standard Autodesk Vault Numbering Generator

function PreSaveDialog_UseVaultNumberingGenerator($document, $isSaveCopyAs, $result) {

	$numberingSchemeName = 'Sequential'  # By default, the Inventor-Save would display a selection dialog if multiple Vault number schemes are active
	if($document.FileName -like '*.iam' -or $document.FileName -like '*.ipt') {
		$numberingSchemeName = 'Model Number'
	}
	if($document.FileName -like '*.idw' -or $document.FileName -like '*.dwg') {
		$numberingSchemeName = 'Drawing Number'
	}

	$vaultNumberingScheme = $vault.NumberingService.GetNumberingSchemes('FILE', 'Activated') | Where-Object Name -eq $numberingSchemeName
	if($vaultNumberingScheme -eq $null) {
		throw "Please activate the '$numberingSchemeName' numbering scheme for files in Vault!" # Error: Abort save with error messagebox and no further Inventor save dialog
	}

	$vaultFileNumber = $vault.NumberingService.GenerateNumberBySchemeId( $vaultNumberingScheme.SchmID, @('')) +
		[IO.Path]::GetExtension($document.FullFileName)


	if ($isSaveCopyAs) {
		$result.FullFileName = "C:\Vault\Copies&Exports\$vaultFileNumber"
	}
	else {
		$result.FullFileName = "C:\Vault\$vaultFileNumber"
	}

 
	if (Test-Path $result.FullFileName) {  # Optional: add this to prevent overwriting existing documents
		throw "The document '$($result.FullFileName)' already exists. Overwriting is not allowed!"
	}

}

Custom Dialog for saving models with an ERP number, using powerGate:

# Note: Install powerGate for a trial. The Sample.ConnectToERP.ps1 is enabled by default. Alternatively, run:
# Import-Module powerGate -ErrorAction Stop; Connect-ERP -Service 'http://demo.powergate.online/PGS/ERP/DemoService' -OnConnect $global:demoERPconnect

Register-InventorEvent -EventName FileSaveAsDialog_Pre -Action {
   param($document, $result)

   if ($document.FileName -notlike '*.ipt' -and $document.FileName -notlike '*.iam') {
      return # skip: continue with default Inventor (or VDS) save dialog
   }

   $customDialog = [Windows.Markup.XamlReader]::Load([Xml.XmlNodeReader]::new([xml] @"
      <Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         Title="Create ERP Item"
         SizeToContent="WidthAndHeight"
         WindowStartupLocation="CenterOwner">

         <StackPanel Margin="20">
            <Label Content="Number"/>
            <TextBox Text="*COMING FROM ERP*" IsReadOnly="True"/>

            <Label Content="Title"/>
            <TextBox Text="{Binding Title}"/>

            <Label Content="Description"/>
            <TextBox Text="{Binding Description}" Height="60"/>

            <Label Content="Material" />
            <TextBox Text="{Binding Material}" />

            <Label Content="Buy" />
            <CheckBox IsChecked="{Binding MakeBuy}" HorizontalAlignment="Left" VerticalAlignment="Center" />

            <Button x:Name="ButtonCreateAndSave"
                  Content="Create &amp; Save"
                  IsDefault="True"
                  Margin="0,15,0,0"/>
         </StackPanel>
      </Window>
"@))

   [Windows.Interop.WindowInteropHelper]::new($customDialog).Owner = [IntPtr]$inventor.MainFrameHWND # this shows the dialog as child of the Inventor window

   $newErpItem = $customDialog.DataContext = New-ErpObject -EntityType 'Item' -Properties @{
      'Material'      = $document._Material
      'Title'         = $document._Title
      'Description'   = $document._Description
      'UnitOfMeasure' = 'Each'
   } -ErrorAction Stop

   $customDialog.FindName('ButtonCreateAndSave').Add_Click({
      $newErpItem.Number = "ERP-{0:D6}" -f (Get-Random -Minimum 0 -Maximum 100000) # this generates a temporary ERP number (the Demo system does not generate Item numbers automatically)
      
      Add-ErpObject -EntitySet 'Items' -Properties $newErpItem
      
      if($?) {  # close the dialog if the ERP item was created successfully
         $customDialog.DialogResult = $true
      }
   })

   if (-not $customDialog.ShowDialog() ) {
      throw [OperationCanceledException] # Cancel: abort the save operation without showing further Inventor save dialogs
   }

   $result.FileName = $newErpItem.Number + [IO.Path]::GetExtension($document.FileName) # continue: save with the ERP item number, without showing further Inventor save dialogs
   # $result.FullFileName now contains the complete target path using Inventor's default location
}

The PopulateFileMetadata event fires when file names and properties are being generated by an Inventor command, before the file naming dialog is displayed to the user.

EventNames:

  • PopulateFileMetadata_Pre

Examples:

PopulateFileMetadata_Pre:

Register-InventorEvent -EventName PopulateFileMetadata_Pre -Action 'PrePopulateFileMetadata'

function PrePopulateFileMetadata() {
	#Write event code here
}