Application Events

The ActivateDocument event notifies the client whenever a document is activated, i.e. when it becomes the top-level document displayed in the active window (for example when a document is opened or the user switches to another document window). _Pre fires before and _Post after the document is activated.
Editing a part in-place within an assembly does not activate the part; the assembly stays the active document (see [NewEditObject](<</code_reference/objects/inventor_event_mappings/application_events/neweditobject>)).

EventNames:

  • ActivateDocument_Pre

  • ActivateDocument_Post

Parameters

Type

Name

Description

Document

document

Object that is being activated

Remarks:

The active document is the top-level document that is being displayed in the active view. This means that in the case of editing a part inside an assembly, the active document will still be the assembly.

Examples:

ActivateDocument_Pre:

Register-InventorEvent -EventName ActivateDocument_Pre -Action 'PreActivateDocument'

function PreActivateDocument($document) {
	#Write event code here
}

Accessing the active Inventor document from Vault event actions:

Register-InventorEvent -EventName ActivateDocument_Post -Action {
	param($document)

	$global:activeDocument = $document
}

Register-VaultEvent -EventName AddVaultFile_Post -Action {
	param($file)

	# Read information from iProperties stored in the Inventor document:
	$category = $global:activeDocument._Category
	$mass = $global:activeDocument._Mass
	$density = $global:activeDocument._Density
	$material = $global:activeDocument._Material

	#Add-ERPObject -EntitySet 'Items' -Properties @{'Cat' = $category; 'Mass' = $mass; 'Den' = $density; 'Material' = $material ... }
}

The ActivateView event notifies the client after a view is activated. A view is equivalent to an Inventor graphics window, so the event fires when the user clicks into a window to work in it. Only _Post is available.

EventNames:

  • ActivateView_Post

Examples:

ActivateView_Post:

Register-InventorEvent -EventName ActivateView_Post -Action 'PostActivateView'

function PostActivateView() {
	#Write event code here
}

The ActiveProjectChanged event notifies the client when the active project is changed, i.e. when a project is activated or when the active project is saved. _Pre fires before and _Post after the active project is changed.

EventNames:

  • ActiveProjectChanged_Pre

  • ActiveProjectChanged_Post

Parameters

Type

Name

Description

String

project

Full file name of the project that has changed

Examples:

ActiveProjectChanged_Pre:

Register-InventorEvent -EventName ActiveProjectChanged_Pre -Action 'PreActiveProjectChanged'

function PreActiveProjectChanged($project) {
	#Write event code here
}

ActiveProjectChanged_Post:

Register-InventorEvent -EventName ActiveProjectChanged_Post -Action 'PostActiveProjectChanged'

function PostActiveProjectChanged($project) {
	#Write event code here
}

The ApplicationOptionChange event notifies the client when the application options are modified. _Pre fires before and _Post after the change, so the values of the options of interest can be read in both events and compared.

EventNames:

  • ApplicationOptionChange_Pre

  • ApplicationOptionChange_Post

Examples:

ApplicationOptionChange_Pre:

Register-InventorEvent -EventName ApplicationOptionChange_Pre -Action 'PreApplicationOptionChange'

function PreApplicationOptionChange() {
	#Write event code here
}

ApplicationOptionChange_Post:

Register-InventorEvent -EventName ApplicationOptionChange_Post -Action 'PostApplicationOptionChange'

function PostApplicationOptionChange() {
	#Write event code here
}

The CloseDocument event notifies the client when a document is closed. _Pre fires before and _Post after the document is closed.
The event is only triggered when the document is really closed. A document that is still referenced by another open document (for example a part of an open assembly) is not closed and therefore does not trigger the event.

EventNames:

  • CloseDocument_Pre

  • CloseDocument_Post

Parameters

Type

Name

Description

Document

document

Object that is being closed. The document being closed is provided before and after. The document is still available after it’s closed, although in a limited sense.

Remarks:

This event can be aborted by throwing an exception inside the action, but only if it is registered with the _Pre suffix.
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:

CloseDocument_Pre:

Register-InventorEvent -EventName CloseDocument_Pre -Action 'PreCloseDocument'

function PreCloseDocument($document) {
	#Write event code here
}

CloseDocument_Post:

Register-InventorEvent -EventName CloseDocument_Post -Action 'PostCloseDocument'

function PostCloseDocument($document) {
	#Write event code here
}

The CloseView event notifies the client before a view is closed. A view is equivalent to an Inventor graphics window, so the event fires when a document window is closed. Only _Pre is available.

EventNames:

  • CloseView_Pre

Examples:

CloseView_Pre:

Register-InventorEvent -EventName CloseView_Pre -Action 'PreCloseView'

function PreCloseView() {
	#Write event code here
}

The DeactivateDocument event notifies the client when a document is deactivated, i.e. when it stops being the active document. _Pre fires before and _Post after the document is deactivated.

EventNames:

  • DeactivateDocument_Pre

  • DeactivateDocument_Post

Parameters

Type

Name

Description

Document

document

Object that is being deactivated.

Examples:

DeactivateDocument_Pre:

Register-InventorEvent -EventName DeactivateDocument_Pre -Action 'PreDeactivateDocument'

function PreDeactivateDocument($document) {
	#Write event code here
}

DeactivateDocument_Post:

Register-InventorEvent -EventName DeactivateDocument_Post -Action 'PostDeactivateDocument'

function PostDeactivateDocument($document) {
	#Write event code here
}

The DisplayModeChange event notifies the client when the display mode of a view changes (wireframe, shaded with hidden edges or shaded without hidden edges). _Pre fires before and _Post after the display mode is changed.

EventNames:

  • DisplayModeChange_Pre

  • DisplayModeChange_Post

Examples:

DisplayModeChange_Pre:

Register-InventorEvent -EventName DisplayModeChange_Pre -Action 'PreDisplayModeChange'

function PreDisplayModeChange() {
	#Write event code here
}

DisplayModeChange_Post:

Register-InventorEvent -EventName DisplayModeChange_Post -Action 'PostDisplayModeChange'

function PostDisplayModeChange() {
	#Write event code here
}

The DocumentChange event notifies the client whenever an action causes any change to a document, supplying the reasons for the change. _Pre fires before the change is made and _Post after the change was made.
The event is not triggered for commands that do not change the document, such as measure and view commands.
Document changes happen very frequently, so the action should start with simple checks to see whether the change is relevant. If possible, use a more specific event instead (for example [ParameterChange](<</code_reference/objects/inventor_event_mappings/modeling_events/parameterchange>) for parameter changes).

EventNames:

  • DocumentChange_Pre

  • DocumentChange_Post

Parameters

Type

Name

Description

CommandTypesEnum

reasonsForChange

This argument indicates the type of change that occurred. The value is from the CommandTypesEnum list, which represents the different categories of changes that can be made. Typically this will be a single value from the list but it can represent multiple values that have been combined together so you need to use bitwise operations to check for a specific change.

Document

document

The document the change is occurring within.

Remarks:

This event can be aborted by throwing an exception inside the action, but only if it is registered with the _Pre suffix.
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:

DocumentChange_Pre:

Register-InventorEvent -EventName DocumentChange_Pre -Action 'PreDocumentChange'

function PreDocumentChange($reasonsForChange, $document) {
	#Write event code here
}

DocumentChange_Post:

Register-InventorEvent -EventName DocumentChange_Post -Action 'PostDocumentChange'

function PostDocumentChange($reasonsForChange, $document) {
	#Write event code here
}

The InitializeDocument event notifies the client when a document is initialized. Initialization is a low-level open: only a part of the document is read to determine related files, the majority of the data is not loaded. When the event fires, the document is not open yet; calling methods or properties of the document in the action forces it to open.
Every document that is opened is initialized first, but a document can also be initialized without being opened (for example the documents referenced by an opened drawing). _Pre fires before and _Post after the document is initialized.

EventNames:

  • InitializeDocument_Pre

  • InitializeDocument_Post

Parameters

Type

Name

Description

Document

document

Object that is being initialized.

Examples:

InitializeDocument_Pre:

Register-InventorEvent -EventName InitializeDocument_Pre -Action 'PreInitializeDocument'

function PreInitializeDocument($document) {
	#Write event code here
}

InitializeDocument_Post:

Register-InventorEvent -EventName InitializeDocument_Post -Action 'PostInitializeDocument'

function PostInitializeDocument($document) {
	#Write event code here
}

The MigrateDocument event notifies the client when a document is explicitly migrated to the data format of the current Inventor version. This happens when the user runs the Migrate command, when the Migrate method is called via the Inventor API, or when a document that needs migration is saved. _Pre fires before and _Post after the document is migrated.

EventNames:

  • MigrateDocument_Pre

  • MigrateDocument_Post

Parameters

Type

Name

Description

Document

document

Object that is being migrated

Remarks

Explicit migration can happen in the following situations:

  • User selects the Migrate command through the User Interface

  • The Document.Migrate method is called via the API on a document needing migration

  • A document needing migration is saved

Examples:

MigrateDocument_Pre:

Register-InventorEvent -EventName MigrateDocument_Pre -Action 'PreMigrateDocument'

function PreMigrateDocument($document) {
	#Write event code here
}

MigrateDocument_Post:

Register-InventorEvent -EventName MigrateDocument_Post -Action 'PostMigrateDocument'

function PostMigrateDocument($document) {
	#Write event code here
}

The NewDocument event notifies the client whenever a new document is created based on a template. _Pre fires before and _Post after the document is created.
The file name of a new document is usually not set until it is saved for the first time. An exception is the Create Component command in an assembly, where the file name is specified as part of the command.

EventNames:

  • NewDocument_Pre

  • NewDocument_Post

Parameters

Type

Name

Description

Document

document

Object that was just created. This is only available in the Post event, as in Pre, the document does not yet exist.

Examples:

NewDocument_Pre:

Register-InventorEvent -EventName NewDocument_Pre -Action 'PreNewDocument'

function PreNewDocument() {
	#Write event code here
}

NewDocument_Post:

Register-InventorEvent -EventName NewDocument_Post -Action 'PostNewDocument'

function PostNewDocument($document) {
	#Write event code here
}

The NewEditObject event notifies the client when the active edit object changes. The edit object is the container that is currently edited by the user: a document, a 2D or 3D sketch, or a drawing sheet. For example, the event fires when a part is activated for in-place editing within an assembly, or when a sketch is created or edited. _Pre fires before and _Post after the edit object changes.
In contrast to [ActivateDocument](<</code_reference/objects/inventor_event_mappings/application_events/activatedocument>), the event also fires when a part is edited in the context of an assembly, because in that case the assembly remains the active document.

EventNames:

  • NewEditObject_Pre

  • NewEditObject_Post

Examples:

NewEditObject_Pre:

Register-InventorEvent -EventName NewEditObject_Pre -Action 'PreNewEditObject'

function PreNewEditObject() {
	#Write event code here
}

NewEditObject_Post:

Register-InventorEvent -EventName NewEditObject_Post -Action 'PostNewEditObject'

function PostNewEditObject() {
	#Write event code here
}

The NewView event notifies the client when a new view is created. A view is equivalent to an Inventor graphics window. _Pre fires before and _Post after the view is created.

EventNames:

  • NewView_Pre

  • NewView_Post

Examples:

NewView_Pre:

Register-InventorEvent -EventName NewView_Pre -Action 'PreNewView'

function PreNewView() {
	#Write event code here
}

NewView_Post:

Register-InventorEvent -EventName NewView_Post -Action 'PostNewView'

function PostNewView() {
	#Write event code here
}

The OpenDocument event notifies the client when a document is opened, either directly by the user (Open command) or indirectly because it is referenced by another document (for example all parts of an assembly are opened together with the assembly). _Pre fires before and _Post after the document is opened.
The event only fires when the document is initially opened. If a file is already loaded because it is referenced by an open assembly, opening it again does not trigger the event.
The order in which this event arrives relative to other events (for example [DocumentChange](<</code_reference/objects/inventor_event_mappings/application_events/documentchange>)) is not guaranteed.

EventNames:

  • OpenDocument_Pre

  • OpenDocument_Post

Parameters

Type

Name

Description

String

fullDocumentName

Output string that specifies the fully qualified name of the document being opened. This is supplied both before and after.

Document

document

The Document object being opened. This is only available in the Post event, as in the Pre, this object does not yet exist.

Examples:

OpenDocument_Pre:

Register-InventorEvent -EventName OpenDocument_Pre -Action 'PreOpenDocument'

function PreOpenDocument($fullDocumentName) {
	#Write event code here
}

OpenDocument_Post:

Register-InventorEvent -EventName OpenDocument_Post -Action 'PostOpenDocument'

function PostOpenDocument($fullDocumentName, $document) {
	#Write event code here
}

The ApplicationReady event notifies the client once, after Inventor has completed its initialization (including all add-ins that are loaded at startup) and is ready for interactive use. Only _Post is available.

EventNames:

  • ApplicationReady_Post

Remarks

Warning

This event is currently not supported, as powerEvents starts up after the Vault log in, when Inventor is already past its ready stage.

Examples:

ApplicationReady_Post:

Register-InventorEvent -EventName ApplicationReady_Post -Action 'PostApplicationReady'

function PostApplicationReady() {
	#Write event code here
}

The SaveDocument event notifies the client whenever a document is saved with the Save or the Save Copy As command. _Pre fires before and _Post after the document is saved.
When an assembly is saved, its dependent documents can be saved as well; the event is also triggered for each of them.

EventNames:

  • SaveDocument_Pre

  • SaveDocument_Post

Parameters

Type

Name

Description

Document

document

Object that is being saved.

Remarks:

The notification is made when the standard Save and the Save Copy As commands are invoked. When assemblies are saved this can also cause the dependent documents to be saved and this event is also fired in those cases.

This event can be aborted by throwing an exception inside the action, but only if it is registered with the _Pre suffix.
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:

SaveDocument_Pre:

Register-InventorEvent -EventName SaveDocument_Pre -Action 'PreSaveDocument'

function PreSaveDocument($document) {
	#Write event code here
}

SaveDocument_Post:

Register-InventorEvent -EventName SaveDocument_Post -Action 'PostSaveDocument'

function PostSaveDocument($document) {
	#Write event code here
}

The TerminateDocument event notifies the client when a document is terminated, i.e. completely closed. Terminating a document is the counterpart of initializing it (see [InitializeDocument](<</code_reference/objects/inventor_event_mappings/application_events/initializedocument>)). _Pre fires before and _Post after the document is terminated.

EventNames:

  • TerminateDocument_Pre

  • TerminateDocument_Post

Parameters

Type

Name

Description

String

fullDocumentName

Output string that specifies the fully qualified name of the document being terminated. This is supplied both before and after.

Document

document

Document object that is being terminated. This is only available in the Pre event, as in the Post event the document is no longer available.

Examples:

TerminateDocument_Pre:

Register-InventorEvent -EventName TerminateDocument_Pre -Action 'PreTerminateDocument'

function PreTerminateDocument($fullDocumentName, $document) {
	#Write event code here
}

TerminateDocument_Post:

Register-InventorEvent -EventName TerminateDocument_Post -Action 'PostTerminateDocument'

function PostTerminateDocument($fullDocumentName) {
	#Write event code here
}

The TranslateDocument event notifies the client whenever a non-Inventor file is translated into Inventor (import) or an Inventor document is translated out to a non-Inventor file (export). _Pre fires before and _Post after the translation.

EventNames:

  • TranslateDocument_Pre

  • TranslateDocument_Post

Parameters

Type

Name

Description

bool

translatingIn

Input Boolean that specifies whether the document is being translated into Autodesk Inventor.

String

fullFileName

The full filename of the document being translated. This is supplied both before and after.

Document

document

The object that is created as a result of the translation. This is only available in the Post event, as in the Pre event, the document has not been created yet

Examples:

TranslateDocument_Pre:

Register-InventorEvent -EventName TranslateDocument_Pre -Action 'PreTranslateDocument'

function PreTranslateDocument($translatingIn, $fullFileName) {
	#Write event code here
}

TranslateDocument_Post:

Register-InventorEvent -EventName TranslateDocument_Post -Action 'PostTranslateDocument'

function PostTranslateDocument($translatingIn, $fullFileName, $document) {
	#Write event code here
}