For now i can control mapping by name of material but the problem is , all in this object material use mapping , exist a way to get all mapping node inside at material and controll all with my rot_var? this object can 1 to multiple materials slots

i think but not work:

ob = context.object
rot_var = ###my variable(0 to 360)
   for s in ob.material_slots:
       if s.material.use_nodes:
           for n in s.material.node_tree.nodes:

                    mapping = n.get("Mapping")                                        
                    mapping.rotation[2] = radians(rot_var)

Edit: i find solution for Mapping:

for slots in ob.material_slots:
    for nodes in slots.material.node_tree.nodes:

        if nodes.type == 'MAPPING':    

            nodes.rotation[2] = radians(rot_var)

but inside i have 2 nodes "MixRGB" i not have idea to get because same name of nodes and not have idea about name of MixRgb

  • $\begingroup$ Ok i find my solution is put name inside the node and to if statement : if nodes.name == "My personal name": $\endgroup$ – Pastrokkio Mar 25 '19 at 2:16
  • $\begingroup$ thats great. please add an answer so others may find the solution. As a new user you may have to wait 24hrs before you can add the answer. $\endgroup$ – rob Mar 25 '19 at 10:23

Wrote following in answer to this q. Noticed you sorted it out, thought I'd post anyway

enter image description here

  • Wrote a utility function to query an objects material nodes. query_mat_nodes(ob, "type", 'MAPPING') returns a list of all mapping type nodes. query_mat_nodes(ob, "name", "Frank") returns a list of all nodes named "Frank" in the objects materials.
  • Added a float property to the object with an update method to set all the mapping nodes on object to this property value. Notice giving the property the unit='ROTATION' will display the value in the UI dependant on the setting for scene rotation unit in units panel. (generally degrees is selected) The property value will always be in radians.
  • For want of a better place I tacked (prepended) draw_prop (a UI draw method) to the node space header to test.

Test script.

import bpy
from math import radians
def query_mat_nodes(ob, key, value):
    return set(n for s in ob.material_slots if s.material and s.material.use_nodes
            for n in s.material.node_tree.nodes if getattr(n, key, None) == value)

def update_map_nodes(self, context):
    for n in query_mat_nodes(self, "type", 'MAPPING'):
        n.rotation.z = self.map_rot

bpy.types.Object.map_rot = bpy.props.FloatProperty(

def draw_prop(self, context):
    self.layout.prop(context.object, "map_rot")

| improve this answer | |
  • $\begingroup$ This is a good alternative! $\endgroup$ – Pastrokkio Mar 25 '19 at 16:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.