Blender How to create integer and boolean node sockets input
HTML-код
- Опубликовано: 6 июн 2022
- As default the type of inputs for node groups can be Vector, Shader, Float or Color. By using the python console you can create inputs of more types, like Integer or Boolean.
If the material is named myMaterial and the group is named myGroup the syntax for an integer input would be
bpy.data.materials['myMaterial'].node_tree.nodes['myGroup'].inputs.new(name = "socket name int", type = "NodeSocketInt")
And for a boolean
bpy.data.materials['myMaterial'].node_tree.nodes['myGroup'].inputs.new(name = "socket name bool", type = "NodeSocketBool")
This video is more of a note to self than a tutorial because I forget things from time to time. Perhaps it's useful for other people too.
Update for blender 3.5
developer.blender.org/docs/re...
bpy.data.materials['myMaterial'].node_tree.nodes['myGroup'].node_tree.inputs.new(type='NodeSocketInt', name='socket name int')
Update for blender 4.0 (not possible to create int or bool)
developer.blender.org/docs/re...
Only these are supported ('NodeSocketVector', 'NodeSocketShader', 'NodeSocketFloat', 'NodeSocketColor')
In blender 4.1 it works again.
bpy.data.materials['myMaterial'].node_tree.nodes['myGroup'].node_tree.interface.new_socket(name='socket name int', in_out='INPUT', socket_type='NodeSocketInt') Кино
Also you can do that with string, material, geometry, collection, texture, object, image even though most of these make no sense in the material editor
neat
thank you
needed this for a mix switcher between different uvs lol
idk why this isnt just exposed in the ui lol
seems to work just fine
edit:
oh i guess there is a slight bug
even if its set to integer it will still take in float inputs
so putting 0.5 into an integer input will still output a 0.5
Glad to hear it's been useful not only to me.
i get an error, "Cannot add socket to built-in node" but i am not, its my own custom node group im trying to add a socket to
The syntax was changed in blender 3.5. In blender 4.0 it's not possible to create int or bool, but it was fixed in blender 4.1. I've updated the description with the new syntax.
This is so helpful!
Can I insert keyframe on bool?
I want to use bool as uv switch but not sure should I use interger and set range in 0 to 1 or just use bool
I'm sorry for the very late reply.
I don't know, I haven't tried. I would say probably because you can pretty much keyframe anything.
Is there a way of changing an already existing input type through some script?
I think it's possible to create one. But I don't know how yet.
In blender 3.5 they changed how to create new inputs. Let's say you have a node group 'NodeGroup'. Now you create inputs with
bpy.data.node_groups['NodeGroup'].inputs.new(name='Int',type='NodeSocketInt')
To change the input type I think you should use tree_socket_change_type
docs.blender.org/api/current/bpy.ops.node.html#bpy.ops.node.tree_socket_change_type
I don't know how to use it in the correct way.
should note
the name of the node group depends on the NODES name
not the node groups name