how to create an attribute whose value is the group name?

   11227   6   0
User Avatar
Member
479 posts
Joined: Dec. 2009
Offline
please see the attached hip file

the last node is to create a new attribute (primitive level, a string attribute) whose value is the name of the group to which a primitive belongs.

What's the python script or hscript to do this for the string value section of the “attribcreate” node?

I'm not sure if it has to do with the “hou.pwd().inputs()” script to get the input node of the current node and then get the name of the group from that input node…

anyway, i don't know the script that can do this. pls help!

thanks!

Attachments:
group name1.hipnc (52.4 KB)

User Avatar
Member
1926 posts
Joined: Nov. 2006
Offline
There isn't a real easy way to do it using just an expression (hscript or python) since dealing with group membership is troublesome. The most straightforward method I think would be to use a ForEach SOP. This allows you to not have to worry about the groups since it just processes each group at a time. You then just need to use a stamps() expression to get the name of the current group for the attribute value.

Attachments:
group_name1_175.hipnc (72.4 KB)

Graham Thompson, Technical Artist @ Rockstar Games
User Avatar
Member
479 posts
Joined: Dec. 2009
Offline
Thank you very much, graham!

following the “foreach” SOP, i want to operate only on those polygons with a specific group name.

I tried to use the Delet SOP to perform this kind of selection, but I don't know if i should use the “delet by pattern” or “delet by expression” option. and what's the pattern string or expression script for these options…

or should i use other SOP to achieve this objective?

Can you guide me on this?

thanks!
User Avatar
Member
1926 posts
Joined: Nov. 2006
Offline
Depending on how you are naming things or how you want to select the groups to use I'd use strcmp or strmatch.

You'd delete by Expression and set your expresion to be strmatch().
Graham Thompson, Technical Artist @ Rockstar Games
User Avatar
Member
479 posts
Joined: Dec. 2009
Offline
hi, graham,

is the Hscript for the “Filter Expression” of the “delet by expression” option something like this, if i want to delet polygons whose “group_name” value is “group1”?

strmatch(hou.pwd().geometry().primAttibs(), “group1”)

or
strmatch(group_name, “group1”)

I can't seem to be able to make it work…

pls guide me again.

Thanks!
User Avatar
Member
9384 posts
Joined: July 2007
Offline
what is your main goal of all this?
do you really need group name as an attribute?
be aware that one primitive can be in many groups

you can delete directly by group
just type group1 in Group field in Delete SOP or Blast SOP

you may be doing all this for some higher purpose so
if you do not have groups anymore, only the primitive attribute called group_name
then type @group_name=“group1” in the Group field of Blast SOP or Delete SOP to delete only the primitives whose group_name attribute value equals “group1”
Tomas Slancik
CG Supervisor
Framestore, NY
User Avatar
Member
479 posts
Joined: Dec. 2009
Offline
thanks, tamte! really appreciate!
  • Quick Links