Skip to end of metadata
Go to start of metadata

First, check the properties for the Material Object:

https://help.sepasoft.com/docs/display/MHD/Material+Objects

There is no option to actually delete a Material, in the MES world we rarely delete objects, instead we disable them and this is exactly what you need to do here using

setEnable(disable)

https://help.sepasoft.com/docs/display/MHD/Object+Functions

so first you will load the MES Object as described in the Material Object function link
and next, you will disable it.


This Script will work to Disable All Material under a Class and Sub Classes in the Class (tested on 2.79.0 SP3)


# The name of the Material Class that you want to disable all children for:
materialClassName = "<change to the target Class Name>"

def disableMaterials(materialClass):
	saveList = system.mes.object.list.createList()
	for childLink in materialClass.getChildCollection().getList():
		if "MaterialDef" == childLink.getMESObjectType().getName():
			childObject = childLink.getMESObject()
			childObject.setEnabled(False)
			saveList.add(childObject)
	system.mes.saveMESObjects(saveList)
	print "Disabled " + str(saveList.size()) + " Material Definitions for " + materialClass.getName()
	for childLink in materialClass.getChildCollection().getList():	
		if "MaterialClass" == childLink.getMESObjectType().getName():
			childObject = childLink.getMESObject()
			childObject.setEnabled(False)
			disableMaterials(childObject)
			childObject.getChildCollection().clear()
			system.mes.saveMESObject(childObject)
			print "Disabled Nested Material Class: " + childObject.getName()
targetMatClass = system.mes.loadMESObject(materialClassName, "MaterialClass")

disableMaterials(targetMatClass)