Hello, fellow blenderers…
I’m here trying to find enlightenment for using uvlayers when creating a new object via python scripting.
I’m developing a import plugin (two, actually), that uses UV layers. I’ve got most of it figured out, but I can’t seem to set the uvlayer property on material.
According to http://www.blender.org/documentation/245PythonDoc/Material.Material-class.html there is a uvlayer property on material (I tought it should be in texture), but I always get this error: AttributeError: ‘Blender Material’ object has no attribute ‘uvlayer’
Trying to see if the documentation is somehow wrong, I tried to assign the parameter on the texture, instead of the material, but I got the following: AttributeError: ‘Blender Texture’ object has no attribute ‘uvlayer’
Here’s some relevants chucks of code:
def createMat(texname): filename = "data/" + texname # texture texture = Texture.New(texname) texture.setType('Image') try: img = Image.Load(filename); texture.image = img except: print ("Can't find texture %s. You'll have to assign it on your own" % filename) mat = Material.New(texname) mat.setTexture(3, texture, Blender.Texture.TexCo.UV) return(mat) (...) # NOTE: This is inside another function, that's why it's indented. That's not an error. # ===== MATERIALS ===== # Assign vertexes to group mat =  # this holds the colbits for the mesh val = 0 for i in range(rsm.getMeshTexCount(Mesh_ID)): name = texnames_utf[i] nodup = removeDup(vertgroups[i]) me.assignVertsToGroup(name, nodup, 1.0, Blender.Mesh.AssignModes.REPLACE) # Create materal for that group x = createMat(name) # x.uvlayer = name # <<- raises error mat.append(x) val += 1 << i # assign materials to the object me.materials = mat ob_act.setMaterials(mat) ob_act.colbits = val # set uvlayers try: for i in range(rsm.getMeshTexCount(Mesh_ID)): me.materials[i].uvlayer = texnames_utf[i] except: print("ERROR: Can't set uvlayer names...Why? WHY!?") # ===== /MATERIALS =====
Can anyone give me a hand? I’m running out of ideas here… If more code is needed, I’ll gladly provide.
Now, that brings up another question: What if I have two textures in the same material using different uv maps?