Hi Everybody……..
The solution to the problem I am having can be very simple, but not being able to solve it.
How to Concat a string and an integer variable say “i” in VEX.
I wanted to create a SOP creating number of groups given by user.
i tried different things like,
newgroup(“group”i);
newgroup(“group”&i);
newgroup(“group”+i);
newgroup(“group”$i);
But nothing is working. Plz Help.
Thanking in advance.
—–iamjaideep80
Concat string and int in VEX
21569 8 2- iamjaideep80
- Member
- 82 posts
- Joined: April 2019
- Offline
- EigenAlex
- Member
- 639 posts
- Joined: July 2005
- Offline
- iamjaideep80
- Member
- 82 posts
- Joined: April 2019
- Offline
- Mario Marengo
- Member
- 941 posts
- Joined: July 2005
- Offline
- pbowmar
- Member
- 7024 posts
- Joined: July 2005
- Offline
- EigenAlex
- Member
- 639 posts
- Joined: July 2005
- Offline
- iamjaideep80
- Member
- 82 posts
- Joined: April 2019
- Offline
Thank u very much, all of u.
I got it, and its working.
But there came another problem.
As far as my knowledge, In case of SOP, Houdini executes all of the Vex program for all the points, one point at a time, And with “ptnum” variable we can get current point being processed. Right? Then why following code is not working.
Don't ask me the use, but i want to write a code that will take all the points, and will put them in different groups, with one point in each group. And the code is…..
sop Test03()
{
string this_grp = sprintf(“group%d”,ptnum);
newgroup(this_grp);
addgroup(this_grp,ptnum);
}
So suppose i have a grid with 100 points , from point number 0 to 99, it should give me 100 groups with corresoponding points in it. But when I did it, only one group “group0” is created and all the 100 points are added to it. Why??????????
When I tried to play with the logic, and wrote something like this……
sop Test03()
{
int i = 0;
for(i = 1;i<=Npt;i=i+1)
{
string this_grp = sprintf(“group%d”,i);
newgroup(this_grp);
if(ptnum==i)
{
addgroup(this_grp,ptnum);
}
}
}
This one is working fine, but is too expensive,
Why the First one is not working, when it is logically correct?????????????/
Waiting for your answer.
——–iamjaideep80
I got it, and its working.
But there came another problem.
As far as my knowledge, In case of SOP, Houdini executes all of the Vex program for all the points, one point at a time, And with “ptnum” variable we can get current point being processed. Right? Then why following code is not working.
Don't ask me the use, but i want to write a code that will take all the points, and will put them in different groups, with one point in each group. And the code is…..
sop Test03()
{
string this_grp = sprintf(“group%d”,ptnum);
newgroup(this_grp);
addgroup(this_grp,ptnum);
}
So suppose i have a grid with 100 points , from point number 0 to 99, it should give me 100 groups with corresoponding points in it. But when I did it, only one group “group0” is created and all the 100 points are added to it. Why??????????
When I tried to play with the logic, and wrote something like this……
sop Test03()
{
int i = 0;
for(i = 1;i<=Npt;i=i+1)
{
string this_grp = sprintf(“group%d”,i);
newgroup(this_grp);
if(ptnum==i)
{
addgroup(this_grp,ptnum);
}
}
}
This one is working fine, but is too expensive,
Why the First one is not working, when it is logically correct?????????????/
Waiting for your answer.
——–iamjaideep80
iamjaideep80 (Jaideep Khadilkar)
- Mario Marengo
- Member
- 941 posts
- Joined: July 2005
- Offline
iamjaideep80
But there came another problem.
Ah, right. I think that's because, in VEX, strings must be uniform (not varying). Still… there seems to be a little kink in VEX's armour , and you can trick it like this:
int i;
for(i=0;i<Npt;i++) {
if(i==ptnum) {
string gname = sprintf(“group%d”,i);
newgroup(gname);
addgroup(gname,i);
}
}
I think that works because it thinks that you're declaring Npt uniform strings – note that gname is built with i, not ptnum. In any case, I believe this is what you'd call a “major hack” and there's no guarantee it might work in the future
However, you can get the exact same functionality you're after (one group per point) by using the Partition SOP. Set the “Entity” to “Points”, and the “Rule” to “group$PT”, and you're done – much safer than that nasty code fragment above.
- iamjaideep80
- Member
- 82 posts
- Joined: April 2019
- Offline
-
- Quick Links