Access Blender Shader Nodes from Python

I wanted to change the value of Shader Node in Blender from the Python side, but it was unexpectedly annoying, so I made a note.

environment

Blender2.81 Windows10

code

Access the shader value like this. Blender is an amateur of Zub, so if you have any details, please comment.

キャプチャ.PNG

import bpy

mat = bpy.data.materials[mat_name]           # get material
node_tree = mat.node_tree                    # node tree of material
nodes = node_tree.nodes                      # nodes array of material
bsdf = nodes.get("Principled BSDF")          # get shader node you want

bsdf.inputs['Metallic'].default_value = 1.0  # set value to inputs
bsdf.inputs['Roughness'].default_value = 0.0 

Recommended Posts

Access Blender Shader Nodes from Python
Access bitcoind from python
Access Oracle DB from Python
How to access wikipedia from python
Access spreadsheets using OAuth 2.0 from Python
Revived from "no internet access" in Python
How to access RDS from Lambda (python)
Blender Python Mesh Data Access Cheat Sheet
Blender 2.9 Python Extrude extrude
sql from python
MeCab from Python
Create wav file from GLSL shader using python3
Use thingsspeak from python
Touch MySQL from Python 3
Use fluentd from python
Changes from Python 3.0 to Python 3.5
Changes from Python 2 to Python 3.0
Python from or import
Use MySQL from Python
Run python from excel
Install python from source
blender, python, spiral staircase
Execute command from Python
Run Blender with python
Operate neutron from Python!
blender, python, sphere behavior
The first step to getting Blender available from Python
Use MySQL from Python
Blender 2.8, Python Cube Scaling
Operate Blender with Python
Operate LXC from Python
Manipulate riak from python
Force Python from Fortran
Use BigQuery from python.
Execute command from python
[Blender x Python] Blender Python tips (11/100)
Get data from database via ODBC with Python (Access)
[Python] Read From Stdin
ODBC access to SQL Server from Linux with Python
Use mecab-ipadic-neologd from python
Problem not knowing parameters when dealing with Blender from Python
Flatten using Python yield from
Call CPLEX from Python (DO cplex)
Deep Python learned from DEAP
Post from Python to Slack
Grammar features added from Python3.6
Cheating from PHP to Python
Make MeCab available from Python3
Blender 2.9, Python Buildings, Cars, Videos
Information obtained from tweet_id (Python)
OCR from PDF in Python
blender, python, spiral staircase, color
Run illustrator script from python
Use MySQL from Anaconda (python)
Anaconda updated from 4.2.0 to 4.3.0 (python3.5 updated to python3.6)
Study from Python Hour4: Object-oriented ②
Study from Python Hour3: Functions
Start / stop GCE from python
Blender 2.9, Python Odd Even Building
Stop Omxplayer from Python code
Switch from python2.7 to python3.6 (centos7)