1
$\begingroup$

I currently have

matName = "Black"

blendfile = addon_dir + "/assets/materials.blend"
selection = "\\Material\\"
material = matName

filepath = blendfile + selection + material
directory = blendfile + selection
filename = material
newMat = bpy.ops.wm.append(filepath=filepath, filename=filename, directory=directory)
mat = bpy.data.materials.get(material)
bpy.context.active_object.data.materials.append(mat)

this appends a material and adds it to the current object. The problem is that it adds a new material slot with the material. How can I make it add the appended material to the active slot?

$\endgroup$
1
  • $\begingroup$ Does this post help you LINK? $\endgroup$
    – Rick Riggs
    Jun 22, 2016 at 1:27

1 Answer 1

4
$\begingroup$

The list of materials that shows in the material properties comes from

obj.material_slots

The index for the one that is selected in that list is

idx = obj.active_material_index

using that you assign a material to that slot with

obj.material_slots[idx].material = mat
$\endgroup$
2
  • 3
    $\begingroup$ Also equivalent to obj.active_material = mat $\endgroup$
    – batFINGER
    Jun 22, 2016 at 7:17
  • $\begingroup$ This works fine! $\endgroup$
    – John Roper
    Jun 22, 2016 at 19:46

You must log in to answer this question.

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