````
### ノード生成スクリプト
### https://qiita.com/yukimituki11/items/dc945cca0b1fc429aa07
import bpy
import json
from mathutils import Vector
# データからノード情報の作成
def make_nodes(node_tree, node_set):
node_list = []
for n_ in node_set:
if "bl_idname" in n_:
# ノードの作成
node = node_tree.nodes.new( n_.pop("bl_idname") )
# アトリビュートの設定
for attr_name in n_.keys():
if hasattr(node, attr_name):
if attr_name == "inputs":
for i_,var_ in enumerate(n_[attr_name]):
if var_: node.inputs[i_].default_value = var_
elif attr_name in ['image', 'object' , 'operation', 'uv_map']:
try:setattr(node, attr_name, n_[attr_name])
except:print('%s:%s was not set' % (node.name, attr_name))
else: setattr(node, attr_name, n_[attr_name])
node_list.append(node)
if "node_links" in n_:
for L in n_["node_links"]:
node_tree.links.new( node_list[ L[0] ].outputs[ L[1] ], node_list[ L[2] ].inputs[ L[3] ] )
obj = bpy.context.active_object
node_tree = obj.active_material.node_tree
#新規にノードグループを作成して その中にノードを生成する場合
# node_tree = bpy.data.node_groups.new('ProjectionNode', 'ShaderNodeTree')
angle = 90
pos_ = [0,-1.0,2.0]
# node_set = [
# {'bl_idname': 'ShaderNodeBsdfPrincipled', 'name': 'Principled BSDF', 'location': Vector((10.0, 300.0)), 'inputs': [[0.07220958173274994, 0.039725761860609055, 0.8000000715255737, 1.0], 0.0, [1.0, 0.20000000298023224, 0.10000000149011612], [0.800000011920929, 0.800000011920929, 0.800000011920929, 1.0], 1.399999976158142, 0.0, 0.0, 0.5, 0.0, 0.5, 0.0, 0.0, 0.0, 0.5, 0.0, 0.029999999329447746, 1.4500000476837158, 0.0, 0.0, [0.0, 0.0, 0.0, 1.0], 1.0, 1.0, [0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0], 0.0]},
# {'bl_idname': 'ShaderNodeOutputMaterial', 'name': 'Material Output', 'location': Vector((300.0, 300.0))},
# {'node_links': [[0, 0, 1, 0]]},
# ]
# クリップボードのテキストを利用して生成したい場合
data_string = bpy.context.window_manager.clipboard
# JSON形式の文字列を使ってPythonのオブジェクトに変換するコード
# JSON形式の文字列をeval()を使用してPythonのオブジェクトに変換し、辞書内のlocationキーについてはVectorオブジェクトに、
# inputsキーについては内部のリストをすべてVectorオブジェクトに変換します。結果を出力すると、正しいPythonオブジェクトが得られます
data_list = eval(data_string)
for item in data_list:
if 'location' in item:
item['location'] = Vector(item['location'])
if 'inputs' in item:
item['inputs'] = [Vector(vec) if isinstance(vec, list) else vec for vec in item['inputs']]
node_set = data_list
print(node_set)
#ノードの作成
make_nodes(node_tree, node_set)
````