# Turning materials on and off

This accounts for skips in Material numbers (ie mats = 1, 2, 3, 5, 6, 9) and also accounts for material names (ie "3 barrier").

``` def TurnOffMat(mat):
matname = "%d" %(mat)
# Assume that the materials category has the substring "aterial" in it
s = SILRestriction()
cats = s.Categories()
material_category = ""
for x in cats:
if "aterial" in x:
material_category = x
if material_category == "":
print "*** Unable to locate material category ***\n"
return
sets = s.SetsInCategory(material_category)
foundOne = False
for x in sets:
# If we have a material name like "3 barrier", then separate out the
# '3' part for comparison.  If the name is just "3", then the following
# command is a no-op.
matnum = s.SetName(x).split(" ")
if matnum == matname:
s.TurnOffSet(x)
foundOne = True
print "*** Unable to locate material %d ***\n" %(mat)
return
SetPlotSILRestriction(s)

def TurnOnMat(mat):
matname = "%d" %(mat)
# Assume that the materials category has the substring "aterial" in it
s = SILRestriction()
cats = s.Categories()
material_category = ""
for x in cats:
if "aterial" in x:
material_category = x
if material_category == "":
print "*** Unable to locate material category ***\n"
return
sets = s.SetsInCategory(material_category)
foundOne = False
for x in sets:
# If we have a material name like "3 barrier", then separate out the
# '3' part for comparison.  If the name is just "3", then the following
# command is a no-op.
matnum = s.SetName(x).split(" ")
if matnum == matname:
s.TurnOnSet(x)
foundOne = True