Creating netboxes with python

   2989   2   1
User Avatar
Member
20 posts
Joined: Sept. 2013
Offline
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)
User Avatar
Staff
3455 posts
Joined: July 2005
Offline
center is the bottom left corner…

box.fitAroundContents()
bbox = hou.BoundingRect(box.position()[0] - pad[0], box.position()[1] - pad[1], box.position()[0] + box.size()[0] + pad[0], box.position()[1] + box.size()[0] + pad[1])
box.setBounds(bbox)
Michael Goldfarb | www.odforce.net
Training Lead
SideFX
www.sidefx.com
User Avatar
Member
20 posts
Joined: Sept. 2013
Offline
goldfarb
center is the bottom left corner…

box.fitAroundContents()
bbox = hou.BoundingRect(box.position()[0] - pad[0], box.position()[1] - pad[1], box.position()[0] + box.size()[0] + pad[0], box.position()[1] + box.size()[0] + pad[1])
box.setBounds(bbox)


That works! Thank you for your help!
  • Quick Links