Skip to content

Instantly share code, notes, and snippets.

@zeffii
Last active August 29, 2015 14:06
Show Gist options
  • Save zeffii/5140bac47295efffc5b6 to your computer and use it in GitHub Desktop.
Save zeffii/5140bac47295efffc5b6 to your computer and use it in GitHub Desktop.
creating input nodes
import bpy
from mathutils import Vector
ng = bpy.data.node_groups[0]
nodes = ng.nodes
n = nodes.active
ndict = n.node_dict
hash = list(ndict.keys())[0]
defaults = ndict[hash]['node_function'].__defaults__
num_params_in = len(defaults)
divided_height = (n.height + (20*num_params_in)) / num_params_in
for idx, (_input, value) in enumerate(zip(n.inputs, defaults)):
a = '{input.name} -> {value}'.format(input=_input, value=value)
print(a)
new_node = None
if isinstance(value, int):
new_node = nodes.new('IntegerNode')
new_node.int_ = value
elif isinstance(value, float):
new_node = nodes.new('FloatNode')
new_node.float_ = value
if new_node:
horizontal_offset = Vector((-170, 0))
vertical_offset = Vector((0, -divided_height))
new_node.location = n.location + horizontal_offset + (vertical_offset * idx)
new_node.hide = True
_from = new_node.outputs[0]
_to = n.inputs[_input.name]
ng.links.new(_from, _to)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment