# Access Mapping node with python

Have problem similar to this but that workaround does not work for me. Empty bpy.data.node_groups

I need to access mapping node with Python so I can change values. This code worked for several times I used script but suddenly it does not work anymore.

bpy.data.node_groups["NodeGroup"].nodes["Mapping"].rotation[2] = math.radians(180)


Also looking at python output when changing values manually and looking at tooltip path output I should use something like this.

bpy.data.node_groups["Shader NodeTree"].nodes["Mapping"].rotation[2] = math.radians(180)


But I get error that Shader Nodetree does not exist.

Can anyone explain what is going on here, am I missing something here?

• – zeffii Oct 19 '15 at 16:28

Since Mapping is a shader tree node, a 'material reference' is required:

import bpy
import math

# get the material
mat = bpy.data.materials['Material']

# get all material nodes
nodes = mat.node_tree.nodes

# get the mapping node
map_node = nodes.get("Mapping")

# set the rotation z component


Direct access:

rot_z = math.radians(180)
bpy.data.materials['Material'].node_tree.nodes['Mapping'].rotation[2] = rot_z


Result:

### Other properties

# set the vector type to 'TEXTURE', 'POINT', 'VECTOR' or 'NORMAL'
map_node.vector_type = "NORMAL"

# set the location components
map_node.translation = (0, 1, 3)

# set scale values
map_node.scale = (1, 0.5, 1)

# use minimum clipping value
map_node.use_min = True
map_node.min = (1,1,1)

# use max clipping value
map_node.use_max = True
map_node.max = (0,0,1)


Result:

For the world environment it's basically the same:

# get the world
world = bpy.data.worlds['World']

# get all material nodes
nodes = world.node_tree.nodes

# get the mapping node
map_node = nodes.get("Mapping")

# set the rotation z component


Direct access:

rot_z = math.radians(180)
bpy.data.worlds['World'].node_tree.nodes["Mapping"].rotation[2] = rot_z
`

Result:

• Thanks this was helpful, I have Mapping node in environmet, I manage to figure out how to access it. – Srecko Micic Oct 19 '15 at 15:31
• @SreckoMicic You are welcome :) I've updated the answer. – p2or Oct 19 '15 at 16:19
• @poor Is there some way to do this in the game engine? – christai Jan 2 '16 at 11:02
• @christai Unfortunately I have no experience with Game Engine. Not sure whether there is a way using nodes for the world background in GE at all, but if this works it's the same process. Otherwise better ask a new question with game engine tag. Hope this helps :) – p2or Jan 2 '16 at 11:30
• @poor Okay, thanks anyway. This topic of accessing material nodes in the Game Engine has been bugging me crazy, so thanks anyway for your input :) – christai Jan 2 '16 at 11:36