Skip to end of metadata
Go to start of metadata

Most MES Objects have specific events that are fired during the life cycle of the object, such as object creation New which fires every time a new instance of the object is created. Events provide the ability to add custom scripting for your application based on certain events. As an example, the Material Lot object has an event every time a new lot number is generated. You could use this to modify how lot numbers are generated.

Events can be viewed and edited from the MES Scripts > MES Object Events section of the Project Browser in Ignition Designer. Whenever an event is fired, an MESScriptEvent object is passed to the event. You can use this object to get information about the event and the object.

For more information on what events are available for which objects, please refer to the 'Object Event' section on each object help page.




Event Types

There are two types of MES Object events, system events and custom events. System events are provided by default and cannot be deleted. Custom events can be created by right-clicking in the MES Events table and selecting New. Script can be added for both system and custom events in the MES Scripts > MES Object Events section of the Project Browser of the Ignition Designer to alter what happens when these events are triggered

Custom events can be created by right-clicking on Custom Trigger Events in the MES Scripts > Custom Trigger Events section of the Project Browser and selecting Add Script. These events will only fire whenever they are called using the system.mes.executeMESEvent scripting function.


Create New Custom Trigger Event Script




Adding Scripts to System Events

Scripts can be added to change the standard behavior of system events and add functionality when custom events are triggered. This is done in the MES Scripts > MES Object Events section of the Project Browser of the Ignition Designer. Click on the event and add the script in the Script window.


System events have default behavior that occurs whenever the event fires. When you add custom script to an event, by default the custom script will execute instead of the default behavior. If you also want the default behavior to occur, add event.runDefaultHandler()

to the custom script.
Code Example
Add Custom Property to New MES Object Example
#Get the object associated with the event 
obj = event.getMESObject()
 
#Read the parameter passed in to the event
kind = event.getParameters().get('Kind')
 
#Based on the kind parameter value, add the appropriate custom property to the MES object.
if kind == 'Bulk':
	obj.addCustomProperty('Avg Width', 'Float4', 'Average Part Width', 'mm', True, False)
elif kind == 'Single':
	obj.addCustomProperty('Actual Width', 'Float4', 'Actual Part Width', 'mm', True, False)

system.mes.saveMESObject(obj)


MESScriptEvent Object

Whenever an event occurs, an MESScriptEvent object is passed to the script window. The following object functions are provided to allow you to access the MES Object itself as well as execute any default behavior.

 runDefaultHandler()
Description

Executes the built-in logic for the event. This allows pre or post logic to be executed around the built-in logic or completely replace the built-in logic. Note that user events will not have a default handler and no logic will be executed if this function is called.

Syntax

runDefaultHandler()


  • Parameters

None

  • Returns

Nothing

 getMESObject()
Description

Returns the MES object that the event is being executed for.

Syntax

 getMESObject()


  • Parameters

None

  • Returns

AbstractMESObject - The MES object associated with the event.

 getParameters()
Description

Return the MESObjectEventParameters object that contains any parameter values

Syntax

getParameters()


  • Parameters

None

  • Returns

MESObjectEventParameters object

 setResult(value)
Description

Set the return result. When a MES events requires a result value, this helper function can be used in place of using the script event.getParameters().put('Result', value)

Syntax

setResult(value)


  • Parameters

boolean Value of the result to return. False will cause the Recipe Event to 'fail out' and abort the intended action (selecting or cancelling a recipe).

  • Returns

Nothing

  • Scope

All



MESObjectEventParameters Object

This object is used with the MESScriptEvent object to pass parameters to the MES object event and holds name value pairs where the name is a string and value is any value type of object. This object is typically used when executing user MES object events to allow passing values to the event script. The system.mes.object.parameters.create() script function can also be used to create a new instance of this object. The following object functions are available:

 get()
Description

Get the value of a parameter by name.

Syntax

get(parameterName)


  • Parameters

String parameterName - The name of the parameter to return the value for.

  • Returns

Object - The type return matches the type when the parameter was added to the collection using the put() function. If the parameter name does not exist in the collection, None is returned.

  • Scope

All

Code Examples
Code Snippet
#Create a new parameter collection instance.
params = system.mes.object.parameters.create()
 
#Add parameters to it.
params.put('Kind', 'Dressing')
params.put('Priority', 'High')
 
#Print the parameter values
print params.get('Kind')
print params.get('Priority')
print params.get('Type')
Output
Dressing
High
None
 put()
Description

Add a name value pair to the parameters collection.

Syntax

put(parameterName, value)

  • Parameters

String parameterName - The name of the parameter to add to the parameters collection.

String value - The value of the parameter.

  • Returns

Nothing

  • Scope

All

Code Examples
Code Snippet
#Create a new parameter collection instance.
params = system.mes.object.parameters.create()
 
#Add parameters to it.
params.put('Kind', 'Dressing')
params.put('Priority', 'High')

 size()
Description

Get the number of parameters in the parameter collection.

Syntax

size()


  • Parameters

None

  • Returns

Integer - description

  • Scope

All

Code Examples
Code Snippet
#Create a new parameter collection instance.
params = system.mes.object.parameters.create()
 
#Add parameters to it.
params.put('Kind', 'Dressing')
params.put('Priority', 'High')

#Print the parameter values.
print params.size()
Output
2
  • No labels