0
$\begingroup$

Is there a way to access the variable that is responsible for the active texture of a certain material for texture painting and change it? It is better to use the image variable itself and not an index. Apart from that, I would like to know if there is a way to set the color for all the tools in texture paint mode instead of just the active one or to prevent their use.

$\endgroup$
1
  • $\begingroup$ For the other aspects of your question, do you mean "tools in texture paint mode" are brushes? and what means "prevent their use"? $\endgroup$
    – lemon
    Commented Feb 3 at 18:03

1 Answer 1

1
$\begingroup$

The active texture in texture paint is given by:

bpy.data.materials['Material'].paint_active_slot

It is modifiable.

And the active material for an object o is:

o.active_material

or its index:

o.active_material_index

You can of course combine the two:

o.active_material.paint_active_slot

PS:

Blender indicates all that hovering its menus:

enter image description here

And:

enter image description here

These tooltips are available if you activate "Python tooltips" in the preferences:

enter image description here


Complement to get the max possible image slot index, for a given material:

import bpy

# get the object
o = bpy.context.object

# get active mat (or the one you want)
mat = o.active_material

# catch nodes of type image texture
images = set(m.image for m in mat.node_tree.nodes if m.type == 'TEX_IMAGE' and m.image is not None)

# get the max index for this material
max_index = len(images) - 1
$\endgroup$
3
  • $\begingroup$ Thanks! It works! Is there a way to check what the index of an image is in the list of possible images of the material and make this image active accordingly? $\endgroup$ Commented Feb 3 at 18:35
  • 1
    $\begingroup$ I'm not sure of that: maybe it's the list of the images in the material nodes sequence. Iterate over the nodes, keep the one that have an image and complete the list. That should be the possible length (so possible index). $\endgroup$
    – lemon
    Commented Feb 3 at 18:44
  • 1
    $\begingroup$ thank you! I found the way. it's something like this: justpaste.it/1qkim $\endgroup$ Commented Feb 3 at 19:19

You must log in to answer this question.

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