Jump to content
Sign in to follow this  
Neon Junkyard

Creating netboxes with python

Recommended Posts

I'm trying to create network boxes with padding in python

However I'm having problems getting the padding to be even and constant on all sides.  I can recreate the built in functionality with fitAroundContents(), but I cant figure out how to correctly figure out the bounding rect from that and then expand it evenly on all sides.  I think this is partially because I'm not correctly calculating the center point from sel.position

Here is my code so far  (my python knowledge is very basic).  Any help is much appreciated!

sel = hou.selectedNodes()[0]
all = hou.selectedNodes()

pos = sel.position()
parent = sel.parent()

box = parent.createNetworkBox()
box.setPosition(sel.position())

# add selected nodes
for node in all:
    box.addItem(node)

# set color
box.setColor(hou.Color(0.3, 0.3, 0.3))

# fit box
box.fitAroundContents()

# fit box
size = box.size()
center = box.position()
pad = hou.Vector2(2, 2)

# set bounding box
bbox = hou.BoundingRect((center[0]-size[0])-pad[0], (center[1]-size[1])-pad[1], (center[0]+size[0])+pad[0], (center[1]+size[1])+pad[1])

# set to bbox
box.setBounds(bbox)

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×