Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Houdini, create 2 network box and note
# region for autocomplete
import hou
from hou import SopNode, Node
hou.attribType.Point = 1
hou.attribType.Prim = 2
hou.attribType.Vertex = 3
hou.attribType.Global = 4
from typing import List, Type, Any, Union, Callable, Tuple
from typing import Tuple
# endregion
import math
def execute():
# find parent node of current node.
selected_nodes = hou.selectedNodes() # type: tuple[hou.Node]
current_nodes = [x for x in selected_nodes if x.isCurrent] # type: List[hou.Node]
if len(current_nodes) == 0:
print("there are no selected node. please select some nodes")
return
parent = current_nodes[0].parent() # type: hou.Node
# create network boxes
parent_network_box = parent.createNetworkBox() # type: hou.NetworkBox
child_network_box = parent.createNetworkBox() # type: hou.NetworkBox
# find good position of boxes, which is center of selected nodes.
list_x_of_selected_nodes = [node.position().x() for node in selected_nodes]
center_x = sum(list_x_of_selected_nodes) / len(selected_nodes)
list_y_of_selected_nodes = [node.position().y() for node in selected_nodes]
center_y = sum(list_y_of_selected_nodes) / len(selected_nodes)
parent_network_box.setPosition(hou.Vector2(center_x, center_y))
child_network_box.setPosition(hou.Vector2(center_x, center_y))
# add selected nodes to box. and resize box.
parent_network_box.addItem(child_network_box)
for selected_node in selected_nodes: # type: hou.Node
child_network_box.addItem(selected_node)
child_network_box.fitAroundContents()
parent_network_box.fitAroundContents()
# set color of network boxes
color_of_network_view = hou.Color(48.0 / 255.0, 48.0 / 255.0, 48.0 / 255.0)
parent_network_box.setColor(color_of_network_view)
color_of_factory_default_sticky_note = hou.Color(90.0 / 255.0, 90.0 / 255.0, 90.0 / 255.0)
child_network_box.setColor(color_of_factory_default_sticky_note)
# create sticky_note
sticky_note = parent.createStickyNote() # type: hou.StickyNote
parent_network_box.addItem(sticky_note)
sticky_note.setPosition(hou.Vector2(center_x, center_y))
sticky_note.setText("title")
sticky_note.setTextSize(0.35)
sticky_note_width = child_network_box.size().x()
stick_note_height = 0.65
sticky_note.setSize(hou.Vector2(sticky_note_width, stick_note_height))
sticky_note_text_color = hou.Color(214.0 / 255.0, 214.0 / 255.0, 214.0 / 255.0)
sticky_note_background_color = hou.Color(82.0 / 255.0, 82.0 / 255.0, 82.0 / 255.0)
sticky_note.setTextColor(sticky_note_text_color)
sticky_note.setColor(sticky_note_background_color)
# move sticky_note on the node whose position is top of nodes
left_most_x = min(list_x_of_selected_nodes)
up_most_y = max(list_y_of_selected_nodes)
# sticky_note_position_x = left_most_x # left_most_xを使うと、child_network_boxの厚み分、ズレが生じてしまうので不可能。
sticky_note_position_x = child_network_box.position().x()
sticky_note_position_y = up_most_y + stick_note_height * 1.5
# sticky_note_position_y = child_network_box.position().y() + stick_note_height * 1.7 # xとは逆に child_nexwork_boxを使うとうまくいかない。
sticky_note_position = hou.Vector2(sticky_note_position_x, sticky_note_position_y)
sticky_note.setPosition(sticky_note_position)
parent_network_box.fitAroundContents()
execute()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.