4
$\begingroup$

In my code below, I want to define a RGB color and specular color:

import bpy
from math import *  

Name = 'Dimi'
bpy.ops.mesh.primitive_cylinder_add(radius = 0.5, depth = 1)
scj = bpy.context.scene
ob = bpy.context.object
me = ob.data
ob.name = Name

ma0 = bpy.data.materials.get("furniture")
ma = ma0.copy()
ma.name = 'furniture_' + Name 
ob.data.materials.append(ma)

ncolor = []

for c in color:
 ncolor.append(c*0.003921)


#defining main color
ma.rgbCol = [ncolor[0]*0.962,ncolor[1]*0.962,ncolor[2]*0.962]
#defining specular color
specCol = [0,0,0]

But in:

#defining main color
ma.rgbCol = [ncolor[0]*0.962,ncolor[1]*0.962,ncolor[2]*0.962]
#defining specular color
specCol = [0,0,0]

That is a blender 2.49 code that I can't find how to make work in Blender 2.74

$\endgroup$
1
  • 2
    $\begingroup$ what render engine are you using cycles, or BI? $\endgroup$
    – David
    Commented Dec 16, 2015 at 3:16

1 Answer 1

2
$\begingroup$

There's a couple of loose-ends in your script, but they aren't a problem for answering the question. The code you are trying to run uses attributes that no longer exist in Blender 2.5 and upwards. In the name of progress they have been replaced.

A few things i'd like to mention:

When you do material.copy() it already appends the new material to bpy.data.materials, you don't need to.

If you are using the old-school 'Blender Internal' render engine then you can set specular and diffuse for materials using:

material_reference.diffuse_color
material_reference.specular_color

code reduced looks like this

import bpy
from math import *  

Name = 'Dimi'
bpy.ops.mesh.primitive_cylinder_add(radius = 0.5, depth = 1)
scj = bpy.context.scene
ob = bpy.context.object
ob.name = Name

ma0 = bpy.data.materials.get("furniture")
ma = ma0.copy()
ma.name = 'furniture_' + Name 

ma.diffuse_color = (0.3, 0.9, 0.7)
ma.specular_color = (1,1,1)

ob.active_material = ma

If you want to script Cycles materials, have a good look at the search results for scripting cycles materials

$\endgroup$
2
  • $\begingroup$ Thanks @zeffii ! This link about cycles material is very good! But I can't find in this link how can to define a colorband. In 2.49 version I can use colorbandDiffuse, but I don't know in 2.74 version $\endgroup$
    – Jimmy
    Commented Dec 16, 2015 at 18:36
  • $\begingroup$ Then you ask a new question. separate question. Sounds like you are looking for a node called ' Color Ramp' $\endgroup$
    – zeffii
    Commented Dec 17, 2015 at 19:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .