Skip to content

Instantly share code, notes, and snippets.

@p2or
Last active May 21, 2023 18:22
Show Gist options
  • Save p2or/fbadce83877a36622720 to your computer and use it in GitHub Desktop.
Save p2or/fbadce83877a36622720 to your computer and use it in GitHub Desktop.
Create Anisotropic Shader #Blender #BSE
# for http://blender.stackexchange.com/questions/32787/example-of-creating-and-setting-a-cycles-material-node-with-the-python-api
import bpy
# get the material
mat = bpy.data.materials['Material']
# get the nodes
nodes = mat.node_tree.nodes
# clear all nodes to start clean
for node in nodes:
nodes.remove(node)
# create emission node
node_ani = nodes.new(type='ShaderNodeBsdfAnisotropic')
node_ani.inputs[0].default_value = (0,1,0,1) # green RGBA
node_ani.inputs[1].default_value = 5.0 # strength
node_ani.location = 0,0
# create output node
node_output = nodes.new(type='ShaderNodeOutputMaterial')
node_output.location = 400,0
# link nodes
links = mat.node_tree.links
link = links.new(node_ani.outputs[0], node_output.inputs[0])
@AjayTalati
Copy link

Yes !!! I think this works 😄 Thank you very much! I learnt a lot!

Slight modifications to match the default settings,

node_emission.inputs[0].default_value = (1,1,1,1) # White RGBA - default if created with GUI
node_emission.inputs[1].default_value = 0.0 # Roughness -- default if created with GUI

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment