VEX concatenate @group_ + chs()

   5931   9   3
User Avatar
Member
459 posts
Joined: Oct. 2011
Offline
Hi
I have an attributewrangle:
if (@primnum < 15) {
concat(“@group_”, chs(“groupname”));
}
This doesn't work and produces no group.
How can i concatenate “@group_” with the user input chs(“groupname”) ?
Is it possible to build @group_groupname programatically?

-b
http://www.racecar.no [www.racecar.no]
User Avatar
Member
2539 posts
Joined: June 2008
Offline
Remember, concat will return a result. You are discarding the result.

Try something like this…

// Primitive index.
int index = 1;

string result = concat(“group_”, chs(“group_name”));
addprimattrib(geoself(), result, index, “some_value_here”);


Note: if the attribute does not exist you use addprimattrib. if it does exist you use setprimattrib.

setprimattrib(geoself(), result, index, “some_value_here”,“set”);
Using Houdini Indie 20.0
Windows 11 64GB Ryzen 16 core.
nVidia 3050RTX 8BG RAM.
User Avatar
Member
459 posts
Joined: Oct. 2011
Offline
Thanks. The problem with addprimattrib is that it doesn't add a group (at least not in the attributewrangle), it just add an attribute with the name “group_mygroup”
If i use the virtual variable @group_mygroup = 1; i get an attribute(group) with the name of group:mygroup listed in the spreadsheet.

-b

EDIT:
substituting the underscore with a colon makes it work:
int index = 1;

string result = concat(“group:”, chs(“groupname”));
addprimattrib(geoself(), result, index, “set”);
EDIT2:
I was wrong. Doesn't work with colon.
http://www.racecar.no [www.racecar.no]
User Avatar
Member
702 posts
Joined:
Offline
It is much simpler than that:

s@my_group = @group + “_” + chs(“groupname”);

no concat needed!
User Avatar
Member
459 posts
Joined: Oct. 2011
Offline
Thanks. I've tried that as well. @group is not a string so it errors with:
Call to undefined binary operator ‘string = float + string’
It's kind of un logical that @group_groupname is a float. I expected it would be an int.

I've also tried with:
s@my_group = “@group” + “_” + chs(“groupname”);
But that results in an attribute called my_group with the value set to “_bound_group_mygroup”
So it's not as easy as it seems.

-b
http://www.racecar.no [www.racecar.no]
User Avatar
Member
702 posts
Joined:
Offline
Not at my pc right now, but is there an itoa function to turn the float to a string?
User Avatar
Member
459 posts
Joined: Oct. 2011
Offline
Thanks.s@my_group = itoa(@group) + “_” + chs(“groupname”);
results in an attribute called “my_group” where the value is set to “0_mygroup” (from the chs())
I think i might have to rethink naming the group like this.

-b
http://www.racecar.no [www.racecar.no]
User Avatar
Staff
730 posts
Joined: Oct. 2012
Offline
If I'm understanding correctly, you could just use the Group Bindings parameter in the Bindings tab to set up a binding to a user-specified group name.
User Avatar
Member
2539 posts
Joined: June 2008
Offline
You could just add a fixed name attribute such as “my_group” to the spreadsheet. Then populate it with the number. At this point you could just use the standard Group node to fetch items based upon that value.

Type in Group name field.
@my_group==0
Using Houdini Indie 20.0
Windows 11 64GB Ryzen 16 core.
nVidia 3050RTX 8BG RAM.
User Avatar
Member
459 posts
Joined: Oct. 2011
Offline
Thanks a lot! Big aha moment with the bindings tab.
- Added one groupbinding with “Group Name” set to `chs(“grpname”)` (the userfield)
- and VEX Parameter set to “group”
- Then in the code: @group = 1;
Thanks.

-b
http://www.racecar.no [www.racecar.no]
  • Quick Links