Skip to content

Context APIs

The APIs defined in this article are used to exchange information between the server application and the custom scripts. The script functions that can be called by the server application must take a pre-defined parameter, called context object, defined to

  • Carry-in the input information from the server to the script;
  • Carry-out the output information from script to the server.

A variety of context objects are defined to support various scripting use cases . They are typically defined to include such information:

  • The context information, such as model space, model, object, from which the script function is invoked;
  • User-defined parameters;
  • The results of the function execution.

Context Classes of Custom Process Scripts

The context classes defined in this group are used to build standalone custom processes.

Class

CustomProcessContext

Description

Class CustomProcessContext defines a context object used to exchange information between the C++ based server application and model-independent custom processes scripted in Python. A model-independent custom process is not associated with any models. It is typically invoked from the global context menu in the UI.

Function

Details

Description

GetParameters

Syntax

GetParameters()

The function returns a sequence of user-defined parameters.

Returns

StringVector

The returned string vector includes all of the user-defined function parameters in the exactly same sequence.

Parameters

none

AddMessage

Syntax

AddMessage(msg)

The function stores a new message, which will be prompted to users in the UI in the same sequence as it is stored.

Returns

none

Parameters

msg: string

String message to be presented to users

GetModelSpace

Syntax

GetModelSpace()

The function returns a reference to the ModelSpace object in the server.

Returns

ModelSpace

The ModelSpace object is a container object hosting all of the FullModel objects in the server.

Parameters

none

Class

ModelCustomProcessContext

Description

Class ModelCustomProcessContext defines a context object used to exchange information between the C++ based server application and model-specific custom processes scripted in Python. A model-specific custom process is related to a FullModel. It is typically invoked from the context menu associated with the related FullModel in the UI.

Function

Details

Description

GetParameters

Syntax

GetParameters()

The function returns a sequence of user-defined parameters.

Returns

StringVector

The returned string vector includes all of the user-defined function parameters in the exactly same sequence.

Parameters

none

AddMessage

Syntax

AddMessage(msg)

The function stores a new message, which will be prompted to users in the UI in the same sequence as it is stored.

Returns

none

Parameters

msg: string

String message to be presented to users

GetModelSpace

Syntax

GetModelSpace()

The function returns a reference to the ModelSpace object in the server.

Returns

ModelSpace

The ModelSpace object is a container object hosting all of the FullModel objects in the server application.

Parameters

none

GetFullModel

Syntax

GetFullModel()

The function returns a reference to the FullModel object, from which the custom process is invoked.

Returns

FullModel

This function is used to retrieve the FullModel object from which the custom process is invoked.

Parameters

none

Context Classes of Plug-in Scripts

The context classes defined in this group are used to plug-in custom functions for model query, validation, transformation, and reporting, etc.

Class

ModelValidationContext

Description

Class ModelValidationContext defines a context object used to exchange information between the validation engine and the model-based custom validation function scripted in Python.

Function

Details

Description

GetParameters

Syntax

GetParameters()

The function returns a sequence of user-defined parameters.

Returns

StringVector

The returned string vector includes all of the user-defined function parameters in the exactly same sequence.

Parameters

none

AddMessage

Syntax

AddMessage(msg)

The function stores a new message, which will be prompted to users in the UI in the same sequence as it is stored.

Returns

none

Parameters

msg: string

String message to be presented to users

GetFullModel

Syntax

GetFullModel()

The function returns a reference to the FullModel object to be validated.

Returns

FullModel

The function returns a reference to the FullModel object to be validated.

Parameters

none

AddObjectValidationResult

Syntax

AddModelValidationResult (type, code className, propName, objectId, message)

Called to report an incident to be included in the validation report

Returns

none

Parameters

type: IncidentType (enum)

Type of the incident, i.e. error, warning, or alert

code: str

Code used to uniquely identify the type of incident

className: str

Name of the class of the reported instance object

propName: str

Name of the related property

objectId: str

rdf:ID of the reported instance object

message: str

Validation description message presented to users

Class

ObjectValidationContext

Description

Class ObjectValidationContext defines a context object used to exchange information between the validation engine and the object-based custom validation function scripted in Python.

Function

Details

Description

GetParameters

Syntax

GetParameters()

The function returns a sequence of user-defined parameters.

Returns

StringVector

The returned string vector includes all of the user-defined function parameters in the exactly same sequence.

Parameters

none

AddMessage

Syntax

AddMessage(msg)

The function stores a new message, which will be prompted to users in the UI in the same sequence as it is stored.

Returns

none

Parameters

msg: string

String message to be presented to users

GetObject

Syntax

GetObject()

The function returns a reference to the instance object where the validation rule is plugged.

Returns

Object

The function returns a reference to the instance object where the validation rule is plugged.

Parameters

none

AddObjectValidationResult

Syntax

AddObjectValidationResult (type, code, message)

Called to report an incident to be included in the validation report

Returns

none

Parameters

type: IncidentType (enum)

Type of the incident, i.e. error, warning, or alert

code: str

Code used to uniquely identify the type of incident

message: str

Validation description message presented to users

Class

MQLFuncCallContext

Description

Class MQLFuncCallContext defines a context object used to exchange information between MQL engine and custom property function scripted in Python.

Function

Details

Description

GetParameters

Syntax

GetParameters()

The function returns a sequence of user-defined parameters.

Returns

StringVector

The returned string vector includes all of the user-defined function parameters in the exactly same sequence.

Parameters

none

AddMessage

Syntax

AddMessage(msg)

The function stores a new message, which will be prompted to users in the UI in the same sequence as it is stored.

Returns

none

Parameters

msg: string

String message to be presented to users

GetObjects

Syntax

GetObjects()

The function returns a collection of objects that the MQL engine is processing before hitting the custom plug-in property function.

Returns

ObjectVector

A collection of objects that the MQL engine is processing before hitting the custom plug-in property function.

Parameters

none

SetOutput

Syntax

SetOutput (output)

The function stores the output string to the context object to be carried over to the MQL engine

Returns

none

Parameters

output: str

Evaluated property value to be carried over to the MQL engine

Class

CustomReportFuncCallContext

Description

Class CustomReportFuncCallContext defines a context object used to exchange information between report generation engine and custom report generation function scripted in Python.

Function

Details

Description

GetParameters

Syntax

GetParameters()

The function returns a sequence of user-defined parameters.

Returns

StringVector

The returned string vector includes all of the user-defined function parameters in the exactly same sequence.

Parameters

none

AddMessage

Syntax

AddMessage(msg)

The function stores a new message, which will be prompted to users in the UI in the same sequence as it is stored.

Returns

none

Parameters

msg: string

String message to be presented to users

GetView

Syntax

GetView()

The function returns a reference to the View object, which encapsulates a custom report dynamically generated.

Returns

View

View is a dynamically-generated object used to contain the information presented in the custom report

Parameters

none

GetFullModel

Syntax

GetFullModel()

The function returns a reference to the FullModel object from which a custom report will be built.

Returns

FullModel

A reference to the FullModel object from which a custom report will be built.

Parameters

none

Class

MTFClassHelperContext

Description

Class MTFClassHelperContext defines a context object used to exchange information between the model transformation engine and the custom class mapping helper function scripted in Python.

Function

Details

Description

GetParameters

Syntax

GetParameters()

The function returns a sequence of user-defined parameters.

Returns

StringVector

The returned string vector includes all of the user-defined function parameters in the exactly same sequence.

Parameters

none

AddMessage

Syntax

AddMessage(msg)

The function stores a new message, which will be prompted to users in the UI in the same sequence as it is stored.

Returns

none

Parameters

msg: string

String message to be presented to users

GetSourceModel

Syntax

GetSourceModel ()

Called to return a reference to the FullModel object which serves as the source model in the model transformation process.

Returns

FullModel

A reference to the FullModel object which serves as the source model in the model transformation process.

Parameters

none

GetTargetModel

Syntax

GetTargetModel()

Called to return a reference to the FullModel object which serves as the target model in the model transformation process.

Returns

FullModel

A reference to the FullModel object which serves as the target model in the model transformation process.

Parameters

none

SourceClassName

Syntax

SourceClassName ()

Called to return the full name of the class which serves as the source class in the model transformation process.

Returns

str

The full name of the class which serves as the source class in the model transformation process. The namespace prefix is included.

Parameters

none

TargetClassName

Syntax

TargetClassName()

Called to return the full name of the class which serves as the target class in the model transformation process.

Returns

Parameters

none

Skip

Syntax

Skip(className, propName)

The function is only used for by-exception model transformation. It tells the model transformation engine not to copy the specified class/property from the source model to target model during the post-exception transformation process.

Returns

none

Parameters

className: str

Full name of the class, including namespace prefix.

propName: str

Full name of the property, including namespace prefix. If empty, the whole class will be skipped.

Class

MTFPropertyHelperContext

Description

Class MTFPropertyHelperContext defines a context object used to exchange information between the model transformation engine and the custom property mapping helper function scripted in Python.

Function

Details

Description

GetParameters

Syntax

GetParameters()

The function returns a sequence of user-defined parameters.

Returns

StringVector

The returned string vector includes all of the user-defined function parameters in the exactly same sequence.

Parameters

none

AddMessage

Syntax

AddMessage(msg)

The function stores a new message, which will be prompted to users in the UI in the same sequence as it is stored.

Returns

none

Parameters

msg: string

String message to be presented to users

GetSourceModel

Syntax

GetSourceModel ()

Called to return a reference to the FullModel object which serves as the source model in the model transformation process.

Returns

FullModel

A reference to the FullModel object which serves as the source model in the model transformation process.

Parameters

none

GetTargetModel

Syntax

GetTargetModel()

Called to return a reference to the FullModel object which serves as the target model in the model transformation process.

Returns

FullModel

A reference to the FullModel object which serves as the target model in the model transformation process.

Parameters

none

SourceClassName

Syntax

SourceClassName ()

Called to return the full name of the class which serves as the source class in the model transformation process.

Returns

str

The full name of the class which serves as the source class in the model transformation process. The namespace prefix is included.

Parameters

none

TargetClassName

Syntax

TargetClassName()

Called to return the full name of the class which serves as the target class in the model transformation process.

Returns

str

The full name of the class which serves as the source class in the model transformation process. The namespace prefix is included.

Parameters

none

GetSourceObject

Syntax

GetSourceObejct ()

Called to return a reference to the Object which serves as the source object in the model transformation process.

Returns

Object

A reference to the Object which serves as the source object in the model transformation process

Parameters

none

GetTargetObject

Syntax

GetTargetModel()

Called to return a reference to the Object which serves as the target object in the model transformation process.

Returns

Object

A reference to the Object which serves as the target object in the model transformation process

Parameters

none

SourcePropertyName

Syntax

SourcePropertyName ()

Called to return the full name of the property which serves as the source property in the model transformation process.

Returns

str

The full name of the property which serves as the source property in the model transformation process. The namespace prefix is included.

Parameters

none

TargetPropertyName

Syntax

TargetPropertyName()

Called to return the full name of the property which serves as the source property in the model transformation process.

Returns

str

The full name of the property which serves as the target property in the model transformation process. The namespace prefix is included.

Parameters

none

PropertyType

Syntax

PropertyType ()

Called to return the type of the property

Returns

PropertyType (enum)

Type of the property, i.e. attribute/association/enumeration

Parameters

none

Skip

Syntax

Skip(className, propName)

The function is only used for by-exception model transformation. It tells the model transformation engine not to copy the specified class/property from the source model to target model during the post-exception transformation process.

Returns

none

Parameters

className: str

Full name of the class, including namespace prefix.

propName: str

Full name of the property, including namespace prefix. If empty, the whole class will be skipped.

Tutorial

To learn how to use the above APIs, check the scripting tutorial.