system.mes.getEquipmentStateOptions

Sepasoft MES Module Suite

system.mes.getEquipmentStateOptions

A function to return equipment state options under the provided parent. This function is built for performance and is not intended to provide all possible states in a tree structure of equipment states, only one level of equipment states at a time.

Syntax

system.mes.getEquipmentStateOptions(equipmentPath, parentUUID, stateTypeFilter)


  • Parameters

String equipmentPath - The path of equipment to return the states for.

String parentUUID - The UUID of the parent equipment state class for the state options being searched for. If "" is passed in, the equipment state class assigned to the equipment will be used.

String stateTypeFilter - The equipment state type filter.

  • Returns

MESObjectList - A MESObjectList object containing MESEquipmentState or MESEquipmentStateClass objects.

  • Scope

All

State Type Filter

Valid options for the State filter parameter are...

'Unknown'
'Unplanned Downtime'
'Planned Downtime'
'Blocked'
'Starved'
'Running'
'Idle'
'Disabled'

Multiple entries can be passed to the stateTypeFilter parameter as a comma separated string. There should be no spaces between names.
Example stateTypeFilter = 'Unplanned Downtime,Planned Downtime'


Code Examples

While the function is built for a single level of equipment states, often users would like to traverse a tree of equipment states. The following script examples provides such.

Code Snippet

Python
# function that will add the state options to the stateOptions list

eqPath=event.source.parent.getComponent('MES Object Selector').equipmentItemPath
filter=event.source.parent.getComponent('Filter').text

def get_state_options(eqPath, parent_uuid, filter, state_options):
    if eqPath != '':
        data = system.mes.getEquipmentStateOptions(eqPath, parent_uuid, filter)
        for item in data:
            parent_uuid = item.getUUID()
            if item.getMESObjectTypeName() == 'EquipmentState':
                state_options.append(item)
            if not item.getChildCollection().isEmpty():
                get_state_options(eqPath, parent_uuid, filter, state_options)

    return state_options

def format_state(state):
    return "[%s] %s, %s" %(state.getName(), state.getStateCode(), state.getStateTypeName())

state_options = get_state_options(eqPath, '', '', [])
filtered_state_options = [state for state in state_options if filter == '' or state.getStateTypeName() == filter]

print "States for %s using filter [%s]" % (eqPath, filter) 
for state in filtered_state_options:
    print format_state(state)

Output

Python
>>> 
States for [global]\Nuts Unlimited\Folsom\Assembly\Saw Mill
[Process Issue] 11, Unplanned Downtime
[Out Of Spec] 12, Unplanned Downtime
[Running] 1, Running
[Idle] 2, Idle
[Blocked] 5, Blocked
[Disabled] 0, Disabled
[Starved] 6, Starved
[Unplanned Downtime] 3, Unplanned Downtime
[Chain Slip] 8, Unplanned Downtime
[Gear 1 Chain Slip] 10, Unplanned Downtime
[Drive Fault] 7, Unplanned Downtime
[Tooling Fault] 9, Unplanned Downtime
[Planned Downtime] 4, Planned Downtime
>>>
Python
# or another way 
# add this code to your Shared Script
#
def get_all_members(obj, obj_list=[]):
	# getting all children of the passed object
	child_objs = [child.getMESObject() for child in obj.getChildCollection().getList()]
	for child in child_objs:
		obj_dict = {}  # creating a dictionary for each child of the passed object
		obj_dict['obj'] = child  # adding the object at the 'obj' key
		obj_dict['name'] = child.getName()  # adding the name at the 'name' key

		parent_dict = filter(lambda item: item['obj'] == obj, obj_list)  # checking to see if the original list already contains the parent of the object
		if parent_dict:
			obj_dict['path'] = "%s/%s" % (parent_dict[0]['path'], child.getName())  # if it exists, append the name of the current object to its parent's path
		else:
			obj_dict['path'] = "%s/%s" % (obj.getName(), child.getName())  # otherwise the path is parent name/child name

		obj_list.append(obj_dict)  # tack it onto the list
		if child.getChildCollection().getList():
			get_all_members(child, obj_list)  # check it for children
	return obj_list
	
def get_all_available_equipment_states(line_path):

	states = system.mes.getEquipmentStateOptions(line_path, '', '')
	
	state_list = []
	
	for state in states:
		if state.getChildCollection():
			dict_list = get_all_members(state)
			state_list.extend([obj['obj'] for obj in dict_list])
		else:
			state_list.append(state)

	filtered_list = filter(lambda x: x.getMESObjectTypeName() == 'EquipmentState' and not x.getChildCollection(), state_list)        
	
	return list(set(filtered_list))
Code
# call the above code with/as  

line_path = '[global]\Nuts Unlimited\Folsom\Receiving\Nut Unloading'

for state in shared.<path>.get_all_available_equipment_states(line_path):
    print state


Sepasoft MES Module Suite