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.
1 Answer
$\begingroup$
$\endgroup$
3
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:
And:
These tooltips are available if you activate "Python tooltips" in the preferences:
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
-
$\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$– lemonCommented 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