FileSaveAsDialog

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
}