Register-InventorEvent
Registers an action that gets invoked before or after the corresponding Inventor event is raised.
Syntax
Register-InventorEvent -EventName <InventorEvent> -Action <Scriptblock | String> [-SourceIdentifier <String>] [<CommonParameters>]
Parameters
Type |
Name |
Description |
Default Value |
Optional |
|---|---|---|---|---|
EventName |
The name of the Inventor event to hook up, including the _Pre or _Post suffix |
no |
||
Scriptblock / String |
Action |
The script block or function name that becomes executed when the according Inventor event is raised |
no |
|
String |
SourceIdentifier |
Unique string which represents the registered event |
new GUID |
yes |
Return type
Event ← on success
empty ← on failure
Remarks
The Cmdlet registers the passed action to a specific Inventor Event.
When a specific method of the Inventor API gets called then the according Inventor event is fired and powerEvents will execute the registered PowerShell action for this event.
The Inventor user gets notified about the Error when an exception is thrown within a registered script block or function.
Registered actions are active as long as they are not unregistered via their SourceIdentifier or Inventor is closed.
Registering multiple actions to the same event will trigger each of the actions in the order they were registered.
By default events are set to EventNotHandled, meaning that Inventor should carry on with its native behavior and trigger further events if registered.
You can hook into 2 different stages for each event, sorted in the sequence they are executed.
Not every event supports both stages, the available ones are listed on the page of each event.
Pre
Gets raised before the actual Inventor API call is executed.
The operation 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.
Not every event can be aborted. Whether a Pre event supports aborting is described on the page of each event.
Post
Gets raised after the actual Inventor API call has been executed.
When the Pre event was aborted or ended with an error, the corresponding Post event, if registered, will not be executed.
Note
Events are only triggered when Inventor is logged into Vault.
The cmdlet can only be used when running directly in an Inventor process.
Examples
Registers a function that fills in iProperties before a document is saved:
Because the action runs in the Pre stage, the iProperties set on the $document are saved together with the document.
The properties are accessed via their system names, so the function works with all Inventor languages.
function Update-DocumentProperties($document) {
if([string]::IsNullOrEmpty($document._Designer)) { # Fill in the designer only if it is empty, so an existing designer is kept
$document._Designer = $env:USERNAME
}
if($document._Description) { # Use upper case descriptions as company standard
$document._Description = $document._Description.ToUpper()
}
Write-Host -Object "Updated iProperties of '$($document.FileName)' before saving" -ForegroundColor Green
}
Register-InventorEvent -EventName SaveDocument_Pre -Action "Update-DocumentProperties"
Aborts the saving of a Content Center part:
The _FamilyId property is only available on the $document of Content Center parts.
$event = Register-InventorEvent -EventName FileSaveAsDialog_Pre -Action {
param($document)
if($null -ne $document._FamilyId) {
Write-Host -Object "Aborting save for Content Center Part..."
throw [OperationCanceledException]
}
}
For more examples, see the FileSaveAsDialog event, e.g. replacing the standard Vault numbering generation for document names
or implementing a custom dialog for saving models with an ERP number using powerGate.