Skip to end of metadata
Go to start of metadata

You have defined a lot of Materials (Products) under one Class and now any edit/update in that Class has become sluggish, may even 
Time Out (Read Time Out).
This will be handled in a more efficient way in our MES Enterprise Version

In the meanwhile, we are recommending that you build smaller classes with a smaller number of Materials. 

The following Script (in the attached window) will help you move your Materials from 

Material Root
 BigClass 
   material n
   material n+too many

like 

to 

Material Root
 BigClassSmallSubClass
   SmallClass1
      material n
      material n+1
    SmallClass2
      material n
      material n+x

like 


 

with this screen

Step-by-step guide

Import the attached Screen

  1. enter the Source Class you want to slice or segment into smaller classes
  2. enter the Material Name pattern you want to move from Source Class to the Target Sub Class UNDER Source Class 
    !! do not forget to add a '*' to select more than one !! like 'Material_1_*"
  3. enter the name of the Target Sub Class that the Material(s) will move to 
  4. click Just DO IT
    depending on the size of your Class, the # of Materials, it could take a little while but will, should, complete without Timeout
  5. to check that your Materials were moved, unfortunately, you will need to close the window and reopen it to re initialize the Material Manager


def create_nested_mat_class(parent_mat_class_name, child_mat_class_name, mat_def_name_search):

    parent_mat_class = system.mes.loadMESObject(parent_mat_class_name, 'MaterialClass')
    
    child_mat_class = system.mes.createMESObject('MaterialClass')
    child_mat_class.setPropertyValue('Name', child_mat_class_name)
    child_mat_class.addParent(parent_mat_class)
    
    begin_filter = system.date.now()
    
    obj_filter = system.mes.object.filter.createFilter()
    
    obj_filter.setPrimaryMESObjectUUID(parent_mat_class.getUUID())
    obj_filter.setMESObjectNamePattern(mat_def_name_search)
    obj_filter.setMESObjectTypeName('MaterialDef')
    
    end_filter = system.date.now()
    
    print 'Filter Creation: %d' % system.date.millisBetween(begin_filter, end_filter)
    
    mat_defs = system.mes.loadMESObjects(obj_filter)
    
    end_mat_load = system.date.now()
    
    print 'Mat Load: %d' % system.date.millisBetween(end_filter, end_mat_load)

    
    
    for mat_def in mat_defs:
        mat_def.removeParent(parent_mat_class)
        parent_mat_class.removeChild(mat_def)
        
        mat_def.addParent(child_mat_class)
        child_mat_class.addChild(mat_def)
        
        # Saving in loop to prevent timeout of saving so many objects at once
        obj_list = system.mes.object.list.createList()
        obj_list.addAll([parent_mat_class, child_mat_class, mat_def])
        system.mes.saveMESObjects(obj_list)
    

# takes all the Material Defintions under Old Material Class
# that follow the patten Material* and moves them to existing New Material Class
# create_nested_mat_class('Old Material Class', 'Child Class to be created', 'Material*')

oldMaterialClass = event.source.parent.getComponent('Source Class').text
newMaterialClass = event.source.parent.getComponent('Target Class').text
material = event.source.parent.getComponent('Material pattern').text

action = "Moving [%s] from [%s] to [%s\%s]" % (material, oldMaterialClass, oldMaterialClass, newMaterialClass)

if system.gui.confirm(action):
	print action
	create_nested_mat_class(oldMaterialClass, newMaterialClass, material)

Mat Class2SubClass.proj


Script courtesy of Derek M.

OEE Material Manager