Jump to content
gfern93

Creating multiple groups by point attribute

Recommended Posts

Hello Odforce, 

 

I'm trying to create groups based on the @P.y attribute of a bunch of vertical lines I have. I am almost there, but I'm not exactly a Vexpert and can't figure out exactly how to assign multiple groups with different names.

I'm able to create a string attribute with the correct name for the groups with 

s@test = sprintf("%f", @P.y);
s@groupname = concat("group_", @test);

 

I tried using setpointgroup(0, @groupname, @ptnum, 1, "set") after this, but it didn't do anything, now I'm just stumped on how to approach assigning this attribute as a group.

Any input would be greatly appreciated! Thank you

 

 

Share this post


Link to post
Share on other sites

Hey Amaya,

I'm guessing that your code probably works, it's just that you can't have a point ( . ), nor a comma ( , ) in a group name.
So in your setup every points of your lines must have had some non-int value, resulting in no groups created at all.

Try multiplying the position by 100 and add it as an integer to your group name, or anything that eliminates the point.

This is my attempt. Keep in mind that you need to set your wrangle to Run Over Detail.

int ptCount = detailintrinsic(0, "pointcount"); // Get the point count

// Initial attributes setup
vector thePos = {0,0,0};
string groupName = "";

for(int i=0; i<ptCount; i++)
{
    thePos = point(0, "P", i); // Get the position
    
    groupName = sprintf("group_%d", thePos[1]*100); // Create the groupName variable
    // For some reasons, the groups doesn't accept commas, nor points ( , . )
    
    //printf("%d ", groupName);
    
    setpointgroup(0, groupName, i, 1);
}

Here's a quick scene with that code.

set_group_by_Y.hip

EDIT :

.. Actually, here's the same scene but with your code, working.

s@test = sprintf("%d", @P.y*100); // %d to have an integer
s@groupname = concat("group_", @test);

setpointgroup(0, @groupname, @ptnum, 1);

set_group_by_Y_1.hip

Edited by Alain2131
  • Thanks 1

Share this post


Link to post
Share on other sites

@Alain2131 thank you so much, I never knew that about groups! I had ended up using as foreach and set the piece attrib to my test attribute. But it's great to know what the issue was! I'm making an asset so I'll post it in the HDA forum in a day or two

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×