Jump to content

Creating groups and attributes from objname


Recommended Posts

Hello!

I currently have a tool that imports a file, in the file there will always be an x amount of primitives named “Thing_0, Thing_1,..” etc. So what I want to do is to group these by name in one go. So I want to have a group from each specific Thing. So the primitive with “Thing_0” name will be in a group called “Thing_0” etc.
Other than that I would also like to apply a value attribute to each group. Thing_0 group would have a value 0 and a Thing_1 would have a value of 1, etc. 

I can do this manually but I want this to be done procedurally since the Thing amounts will be different for each file.

Thanks in advance!

Edited by hampuseh
Link to comment
Share on other sites

For creating groups based on different names/values you can use the partition SOP: http://www.sidefx.com/docs/houdini/nodes/sop/partition.html

For apply the values there are different options. For sure you can use the groups previously created for assign them. The values of thing_0 will always be 0, thing_1 will always be 1 and so on or you need to be able to set them if needed?

If you don't need to set them manually you can run a loop on the groups and assign the current iteration value for each group.

Link to comment
Share on other sites

What you mean by "named"? If you mean they have an attribute called "name" (or any attribute for that matter), that's already a group for all intentions and purposes. If you really want to make it a normal group, you can wrangle something like

setprimgroup(0, s@name, @primnum, 1); 

As for setting the value, something like

i@attrib = atoi(s@name[-1])

 

 

Link to comment
Share on other sites

Thanks for your answer!

I don't think I was clear enough when I tried to describe my problem. 
 

How I want to do it is to first assign a attribute value to each respective primitive named "thing_0 = value 0, thing_1 = value 1 etc" 

I then know that I can partition and create groups by that attribute value. However I don't know how to assign that attribute value to my primitives procedurally. 

At this time I have made  4 different attributecreates and manually assigned value 1-4 and then grouped them with the partition sop. This works but not procedurally.

Link to comment
Share on other sites

3 minutes ago, vtrvtr said:

What you mean by "named"? If you mean they have an attribute called "name" (or any attribute for that matter), that's already a group for all intentions and purposes. If you really want to make it a normal group, you can wrangle something like


setprimgroup(0, s@name, @primnum, 1); 

As for setting the value, something like


i@attrib = atoi(s@name[-1])

 

 

Sorry for not being specific enough. What I mean with "named" is the objects objname file path. Looks something like this: /stuff/stuff/stuff/stuff/Thing_0. 
But maybe if I could convert the path obj filepath to a singular name your approach would work aswell? Thanks for your reply.

Link to comment
Share on other sites

Yes you can use both VEX or Python for that. Both can split the path based on the last "/" and take the last part.

With VEX: 

string thing_name[] = split(s@path,"/");
s@name = thing_name[-1];

 

With python (if you have previously created the name attribute): 

node = hou.pwd()
geo = node.geometry()

# Add code to modify contents of geo.
# Use drop down menu to select examples.

for prim in geo.prims():
    path = prim.attribValue("path");
    name = path[path.rfind("/")+1:]
    prim.setAttribValue("name",name);

 

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