Atom's 2.5 Material Function Library

Hi All,

As I work my way through the BlendText conversion, I have come up with a few test suites to iron out bugs.

Here is my recent work on converting the materials functions I will need for the BlendText engine:

import bpy

def fetchIfObject (passedName= ""):
        result =[passedName]
        result = None
    return result

def returnTexturesNameList(passedMaterialName):
    result = []
    tempMat = returnMaterialByName(passedMaterialName)
    l = len(tempMat.texture_slots)
    if l > 0:
        for ts in tempMat.texture_slots:
            if ts != None:
    return result

def returnTextureByName(passedName):
    result = None
    for t in
        if == passedName:
            result = t
    return result
def returnMaterialsNameList():
    result = []
    for m in
    return result
def returnMaterialByName(passedName):
    result = None
    for m in
        if == passedName:
            result = m
    return result

def createNewMaterial (passedName):
    tempMat =
    if tempMat != None:
        tempMat.diffuse_color = (0.1,0.2,0.3)
        tempMat.diffuse_shader = 'LAMBERT'
        tempMat.diffuse_intensity = 1.0
        tempMat.specular_color = (0.9,0.9,0.9)
        tempMat.specular_shader = 'COOKTORR'
        tempMat.specular_intensity = 0.5
        tempMat.alpha = 1.0
        tempMat.ambient = 0.3
        tempMat.emit = 0.2
    return tempMat

def aquireOrCreateMaterial(passedName):
    tempMat = returnMaterialByName(passedName)
    if tempMat == None:
        tempMat = createNewMaterial(passedName)
    return tempMat

def assignMaterial(passedObjectName, passedMaterial, passedLink = "DATA"):
    result = False
    tempObject = fetchIfObject(passedObjectName)
    if tempObject != None:
        if tempObject.material_slots.__len__() > 0:        
            tempObject.material_slots[0].material = passedMaterial
            tempObject.material_slots[0].link = passedLink 
            print("OBJECT Slot #0 " +
            tempObject.material_slots[tempObject.material_slots.__len__() - 1].material = passedMaterial
            tempObject.material_slots[tempObject.material_slots.__len__() - 1].link = passedLink
            print("OBJECT Added to end.") 
        result = True       
        print("No object called [" + passedObjectName + "].")
    return result

# Program starts here.
lstMaterialNames = returnMaterialsNameList()
name = "Material"        #Use a material name already in the scene.
n = returnMaterialByName(name)
print (n.diffuse_color)
lstTextureNames = returnTexturesNameList(name)
tempName = lstTextureNames[0]
tempTexture = returnTextureByName(tempName)

myMaterial = aquireOrCreateMaterial("myMAT")    #Fetch existing material or create new one if it does not exist.
#r = assignMaterial("Cube",myMaterial,"OBJECT")  #Override default link type of "DATA".
r = assignMaterial("Cube",myMaterial)           #Defaults to "DATA" if 3rd parameter is ommited.

The assign material to object function makes the assumption that if you already have a list of materials and you are assigning a material, the new assignment goes to slot #0. This could be expanded upon, of course, but for BlendText, this will always be the case because the script is managing the materials.