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')
  • КиноКино

Комментарии • 11

  • @XyozaxeR
    @XyozaxeR 2 месяца назад

    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

  • @tylerherr4288
    @tylerherr4288 Год назад

    neat
    thank you
    needed this for a mix switcher between different uvs lol

    • @tylerherr4288
      @tylerherr4288 Год назад

      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

    • @iar7187
      @iar7187  Год назад

      Glad to hear it's been useful not only to me.

  • @chems
    @chems 3 месяца назад

    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

    • @iar7187
      @iar7187  3 месяца назад

      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.

  • @SScheffera
    @SScheffera 8 месяцев назад

    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

    • @iar7187
      @iar7187  5 месяцев назад

      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.

  • @Tatsumi7886
    @Tatsumi7886 11 месяцев назад

    Is there a way of changing an already existing input type through some script?

    • @iar7187
      @iar7187  11 месяцев назад +2

      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.

  • @tylerherr4288
    @tylerherr4288 Год назад

    should note
    the name of the node group depends on the NODES name
    not the node groups name