Jump to content

Creating netboxes with python


Neon Junkyard

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)

 

Link to comment
Share on other sites

  • 1 year later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...