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 Production Model section of the 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 Production Model section of the Ignition Designer to alter what happens when these events are triggered

Custom events can be created by right-clicking in the MES Events table in the Production Model section of the Ignition Designer and selecting 'New'. These events will only fire whenever they are called using the system.mes.executeMESEvent scripting function.



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 also done in the Production Model section of the Ignition Designer by right-clicking on the event and selecting 'Edit'.

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.

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

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.

Description

Return the MESObjectEventParameters object that contains any parameter values

Syntax

getParameters()


  • Parameters

None

  • Returns

MESObjectEventParameters object

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

Value of the result to return

  • 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:

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
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')

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