Jump to content

How to add a Group field to my OPs that's found in the standard SO


magneto

Recommended Posts

I am talking about the Group field that allows you to type into but also have a drop down where Houdini provides you with all the available groups.

Is it possible to have the same control in custom OPs/DAs so I can limit my OP to a particular group?

Thanks :)

Edited by magneto
Link to comment
Share on other sites

Depending on what you are doing you can usually get that information for free. If your asset has nodes internally that need to accept a group and have the normal prim/point Group parameter with the menu, the easiest thing to do is to just promote that parameter directly to your asset. It will create a String menu parameter that has its menu script using opmenu -l and pointing to that node/parameter. This basically asks that group parm for its contents and displays it up one level.

However, if you are using something that doesn't have that (say a Python SOP), you'll have to build the menu yourself by doing something like this in the menu script section of the parameter:

sopnode = hou.pwd()
# List of tokens/labels to return.
menu = []
# Make sure there is an input node before asking for its geometry.
if sopnode.inputs():
    # Optionally add in '*' for all groups.
    menu.extend(("*", "*"))
    geo = sopnode.inputs()[0]
    for group in geo.pointGroups():
        name = group.name()
        menu.extend((name, name))

return menu

Edited by graham
  • Like 1
Link to comment
Share on other sites

Depending on what you are doing you can usually get that information for free. If your asset has nodes internally that need to accept a group and have the normal prim/point Group parameter with the menu, the easiest thing to do is to just promote that parameter directly to your asset. It will create a String menu parameter that has its menu script using opmenu -l and pointing to that node/parameter. This basically asks that group parm for its contents and displays it up one level.

However, if you are using something that doesn't have that (say a Python SOP), you'll have to build the menu yourself by doing something like this in the menu script section of the parameter:

sopnode = hou.pwd()
# List of tokens/labels to return.
menu = []
# Make sure there is an input node before asking for its geometry.
if sopnode.inputs():
    # Optionally add in '*' for all groups.
    menu.extend(("*", "*"))
    geo = sopnode.inputs()[0]
    for group in geo.pointGroups():
        name = group.name()
        menu.extend((name, name))

return menu

Thanks Graham, just tried it but got no attribute called pointGroups on geo. Do I have to create an attribute with that name? I assume it's not the name of the parameter of my group control, right?

Still checking the net while on vacation??? ;)

(ahem.. shame on me)

No vacation for the wicked :D

Link to comment
Share on other sites

Thanks Graham, that's awesome. I just tried it, the menu at least pop-ups, but doesn't show any groups that I created upstream? Do I have to add in more code for that?

Also I assume in the code I will have to get the name of the menu item clicked and set the text of the textbox to this value?

Lastly how can I read this value back from the textbox? Is there a single function that can get points/prims whether the user typed in point/prim indices or a group name or just *, etc?

Thanks again :)

Link to comment
Share on other sites

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...