Page MenuHome

material_slots[i].link reverts to 'DATA' after material_slots[i].material = m0
Closed, ResolvedPublic

Description

System Information
Linux bubastis 3.18.12-gentoo #1 SMP Tue Jun 16 16:26:19 EDT 2015 x86_64 Intel(R) Core(TM) i7-4800MQ CPU @ 2.70GHz GenuineIntel GNU/Linux
01:00.0 VGA compatible controller: NVIDIA Corporation GK107GLM [Quadro K1100M] (rev a1)

Blender Version
Broken: 2.74

If I attempt to use python to set a per-object material with code like this:

obj.material_slots[1].link = 'OBJECT'
print(obj.material_slots[1].link)
obj.material_slots[1].material = mat
print("argh "+obj.material_slots[1].link)

somehow the material_slots[1].link reverts to 'DATA'

Here is a quick python script you can run while the cube is the active object:

import bpy

obj = bpy.context.active_object

while len(obj.data.materials)<2:
    obj.data.materials.append(None)

obj.material_slots[1].link = 'OBJECT'
obj.material_slots[1].material = bpy.data.materials[0]

print(obj.material_slots[1].link)

Notice how it prints out 'DATA', despite the fact that we set it to 'OBJECT' .

Event Timeline

Robert Forsman (mutantbob) created this task.
Robert Forsman (mutantbob) raised the priority of this task from to Needs Triage by Developer.

The script which you showed is wrong.
Did you carry out the script?
I think that an error occurs.
I show a simple example.

import bpy

obj = bpy.data.objects['Cube']

m = bpy.data.materials.new('Material01')
me = obj.data
me.materials.append(m)
obj.material_slots[0].link = 'OBJECT'
obj.material_slots[0].material = m