hampuseh Posted January 28, 2019 Share Posted January 28, 2019 (edited) 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 January 28, 2019 by hampuseh Quote Link to comment Share on other sites More sharing options...
Andrea Posted January 28, 2019 Share Posted January 28, 2019 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. Quote Link to comment Share on other sites More sharing options...
vtrvtr Posted January 28, 2019 Share Posted January 28, 2019 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]) Quote Link to comment Share on other sites More sharing options...
hampuseh Posted January 28, 2019 Author Share Posted January 28, 2019 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. Quote Link to comment Share on other sites More sharing options...
hampuseh Posted January 28, 2019 Author Share Posted January 28, 2019 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. Quote Link to comment Share on other sites More sharing options...
Andrea Posted January 28, 2019 Share Posted January 28, 2019 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); Quote Link to comment Share on other sites More sharing options...
hampuseh Posted January 28, 2019 Author Share Posted January 28, 2019 Thanks alot you two! I got it working with both of your help Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.