bpy.ops.material.new()

bpy.ops.material.new() applies a default material to the selected object.

1.How can I rename this material from the default “Material” into one of my choice?

2.How do I change the properties like diffuse color, translucency for this new material?

Please give me the shortest and sweetest code.
Thank you.

bpy.ops.material.new() makes a new material, AFAIK doesn’t apply it to the active object.

The code below does the same thing twice. It shows the code for using ops or doing the same thing using API calls



import bpy

context = bpy.context

#using ops 

bpy.ops.material.new()
new_mat = bpy.data.materials[-1]  # the new material is the last one in the list
new_mat.name = "NAME"

# using API

new_mat = bpy.data.materials.new("NAME")
# because there is already a material with name NAME from the op this will have name NAME.00x 
print(new_mat.name)
# setting the diffuse color

new_mat.diffuse.color = (0,0,0) # black


# assigning the new material to the active object
# assume you have a mesh object as context.object
# using ops

bpy.ops.object.material_slot_add()

# the new slot will be the active one 

context.object.active_material = new_mat


# using API
# add the material to the mesh's materials

mesh = context.object.data
mesh.materials.append(new_mat)

Get used to using the console. It makes working this stuff out very simple.

Thanks mate
I am actually from procedural background
It is taking time for me to memorize bpy object model
Can you tell me where can i get a complete documentation of bpy?
The official documentation at blender.org seems to incomplete or written disorderly

API docs: http://www.blender.org/documentation/250PythonDoc/

you may have a look at bpy.types, most data structures and their methods are listed there (and not in bpy.data, where the data instances are found later)