0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

[HoudinixPyhon] HDAのInputとOutputを動的に増減

0
Posted at

はじめに

HDAに入出力できるノードの数を可変にしてみます

タイトルなし-2026-03-16 03 23 32(copy)-2026-03-29 19 30 32(copy)-2026-04-02 08 46 21(copy).gif

GIF動画だとちょっと分かりづらいですが
Multiparm Blockの数によって入出力できるノードの数を可変にし
ノードを入力すると、自動的にノードのパスがパラメータにセットされています

Python Module

import hou
from typing import Any


class HDA:
    def __init__(self, kwargs: dict[str:Any]):
        self.HDA_node: hou.SopNode = kwargs["node"]
        self.deifinition = self.HDA_node.type().definition()

    def get_count(self, parmName: str) -> int:
        count = self.HDA_node.evalParm(parmName)
        return count

    def variable_max_inputs(self, count: int):
        self.deifinition.setMaxNumInputs(count)

    def variable_max_outputs(self, count: int):
        self.deifinition.setMaxNumOutputs(count)

    def create_output_nodes(self, count: int):

        # 一度すべてのoutputノードを消してから再生成
        nodes = self.HDA_node.children()
        for i, n in enumerate(nodes):
            if n.name() == f"output{i}":
                n.destroy()

        for c in range(count):

            output = self.HDA_node.createNode("output", f"output{c}")

            # 内部の入力中継ノード (Sub-Network Input #) を取得
            input = self.HDA_node.indirectInputs()[c]

            output.setInput(0, input)

        self.HDA_node.layoutChildren()

    def set_parm_from_input(self, count: int):

        for i in range(count):
            input_parm = self.HDA_node.parm(f"input{i+1}")
            node = self.HDA_node.input(i)

            # inputがないときは""を入れる
            if node == None:
                input_parm.set("")
            else:
                path = node.path()
                input_parm.set(path)


def change_multi(kwargs):
    hm = HDA(kwargs)
    hm.variable_max_inputs(hm.get_count("multi"))
    hm.variable_max_outputs(hm.get_count("multi"))
    hm.create_output_nodes(hm.get_count("multi"))


def on_input_change(kwargs):
    hm = HDA(kwargs)
    hm.set_parm_from_input(hm.get_count("multi"))

Callback Script

hou.phm().change_multi(kwargs)

image.png

OnInputChanged

import hou

node_module = kwargs["node"].hdaModule()
node_module.on_input_change(kwargs)

image.png

まとめ

input = self.HDA_node.indirectInputs()[0]

これで内部の入力中継ノード (Sub-Network Input #) を取得ができる
ということは初めて知りました

簡単そうに見えて奥が深いですね。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?