Add Material with 2.25 API


(S68) #1

I was hacking around with an old script I was preparing and never finished because 2.23 API didn’t allow to easily add materials, hoping that new 2.25 API could help…

Script is (in a nutshell)

        
from Blender import *
from random import random

def sub1():

  me=Mesh.New()
  for j in range(0,4):
    x = random()
    y = 0
    z = 0

    me.addVert((x,y,z))

  return me

sc = Scene.getCurrent()
ob = Object.New('Mesh','bof')

me = sub1()

mat = Material.New('bof')
mat.rgbCol=(0.8,0.9,1.0)
mat.setHaloMode() 

me.link(mat)
ob.link(me)
sc.link(ob)


Which looks fine as for API docs http://www.blender.org/modules/documentation/225PythonDoc/index.html

BUT

I get my four vertices, and my material, but the material tab is RED, Material looks unassigned and rendering tends to crash everithing :frowning:

What’s wrong?

(Please note I don’t need faces, just vertexes, it is a halo stuff)

Thanx in advance

Stefano


(eeshlo) #2

Again, another 2.25 bug, this worked in the last Blenderleague testversion, but not in the real 2.25.
The only solution seems to be linking the materials to the object instead of the mesh, replace the last three lines with this:


ob.link(me)
ob.setMaterials([mat])
ob.materialUsage('Object')
sc.link(ob)

I also wouldn’t rely too much on the 2.25 docs, there are things in there that never made it to the release.


(S68) #3

I Know You Were The One With The Answer (TOWTA)

I’ll try…

yes, there’s a LOT of things in that doc which do not work at all…

Thanx :slight_smile:

Stefano