Map To - How to?

Hi

I try to make a small script for the alpha layer texture / image creation.

Script reads the selected object UV-texture name and creates 1:1 size and similar named alpha layer texture / image for it.

At the end the script would open the ‘Alpha-painting’ window for the alpha layer editing & render result viewing.

Microversion 0.000001


import Blender
from Blender import*
img = ''
sel = Object.GetSelected() #get selected object
if sel: #if we have an existing object
    if sel[0].type=='Mesh': #and it is a mesh
        me = sel[0].getData(mesh=True) #get the mesh dat
        for f in me.faces:
            try:
                if f.image:
                    img = f.image.name
                    size = f.image.getSize()
                    break # 
            except ValueError:
                pass
        name = img[:img.find('.')]+'_a'+img[img.find('.'):] # create a name for the alpha texture image 
        timg = Texture.New(img[:img.find('.')]+'_a') # create a name for the alpha texture
        timg.setType('Image')
        limg = Image.Load(name)
        timg.image = limg
        
        mat = Material.Get('alpha') # pre made material name
        mtextures = mat.setTexture(0,timg)

Problem
How I can do a needed ‘Map To’ settings for the texture from python? Marked with yellow color in linked picture:
http://www.warezhouze.1g.fi/kuvat/Blender_python/ALIT01.jpg/full

I have been reading the API docs about the Texture module and MTex class, but I really don’t know how to use it.
http://www.blender.org/documentation/244PythonDoc/Texture-module.html

http://www.blender.org/documentation/246PythonDoc/Texture-module.html#TexCo

Thanks for pointing the right direction :slight_smile:

Here is the code so far.


import Blender
from Blender import*

def alpha_img(img,size, me):
        name = img[:img.find('.')]+'_a'+img[img.find('.'):]
        aimg = Image.New(name,size[0],size[1],24)
        aimg.pack()
        aimg.save()
        
        timg = Texture.New(img[:img.find('.')]+'_a')
        timg.setType('Image')
        limg = Image.Load(name)
        timg.image = limg

        mats = me.materials
        nmat = mats[0].getName()
        mat = Material.Get(nmat)

        mtextures = mat.setTexture(0,timg, Texture.TexCo.UV, Texture.MapTo.ALPHA)
        ctex = mat.getTextures()
        for c in ctex:
            if c:
                c.blendmode = 3
                c.noRGB = True
                c.neg = True
                c.stencil = True


def get_obj():
    img = ''
    sel = Object.GetSelected() #get selected object
    err=0
    if sel: #if we have an existing object
        if sel[0].type=='Mesh': #and it is a mesh
            me = sel[0].getData(mesh=True) #get the mesh dat
            
            for f in me.faces:
                try:
                    if f.image:
                        img = f.image.name
                        size = f.image.getSize()
                        
                        try:
                            tchk = Texture.Get(img[:img.find('.')]+'_a')
                            print 'The',sel[0].getName(),'object already has a  "',img[:img.find('.')]+'_a "  alpha texture.'
                            
                        except NameError:
                            alpha_img(img,size, me)                             
                            break

                except ValueError:
                    pass                
                
get_obj()
Blender.Window.RedrawAll()