Get String of Edge Group like this: p36-37-38 p12-13

   1059   4   1
User Avatar
Member
1004 posts
Joined: 4月 2017
Offline
I made a vex script that takes the "Base Group" of a group sop and does magical things with it. Its in this format: p36-37-38 p12-13

My problem is when I create a group without using a group sop, I don't know how to get that string. For exemple, if I group points and I use the group promote sop to convert to edges, how can I get the string of it?

-Olivier
Edited by olivierth - 2023年6月6日 17:58:38

Attachments:
Houdini_string_of_group_01.JPG (66.2 KB)
Houdini_string_of_group_02.JPG (62.1 KB)

User Avatar
Member
56 posts
Joined: 4月 2008
Offline
In this situation I think you can try coding in vex like this for getting the string.
Hope this helps.

function int[] unique_elements(int arr_orig[])
{
    int arr[]=sort(arr_orig);
    for (int i=0;i<len(arr);i++)
    {
        while(arr[i]==arr[i+1]) pop(arr,i);
    }
    return arr;
}


function string[] get_uniq_elements(string array[])
{
    //
    int size=len(array);
    for(int i=0;i<size;i++)
    {
        for(int j=i+1;j<size;j++)
        {
            if(array[i]==array[j])
            {
                array[i]==array[j];
                for(int k=j;k<size-1;k++)
                {
                    array[k]=array[k+1];
                }
                size--;
                j--;
            }
        }
    }
    
    //
    string uniq_array[];
    for(int i=0;i<size;i++)
    {
        push(uniq_array,array[i]);
    }
    return uniq_array;
}
//----------------------------------------------

//
int tmp_pts[]=expandedgegroup(0,'ppp');
int pts[]=unique_elements(tmp_pts);

//int nb_pts2[];
string edges[],edge;

foreach(int pt;pts)
{
    int nb_pts[]=neighbours(0,pt);
    for(int i=0;i<len(nb_pts);i++)
    {
        if(find(pts,nb_pts[i])>=0)
        {
            edge = sprintf("p%g-%g ", min(pt, nb_pts[i]), max(pt, nb_pts[i]));
            if (inedgegroup(0, "ppp", min(pt, nb_pts[i]), max(pt, nb_pts[i]))) push(edges,edge);
        }
    }
    
}



string edges2[]=get_uniq_elements(edges);
printf("%d\n",len(edges2));
printf("-----------------\n");


string grp_edges="";
foreach(string cur_edge;edges2)
{
    grp_edges+=cur_edge;
}

s@grp_edges=grp_edges;
Edited by Benyee - 2023年6月19日 11:26:41

Attachments:
Get_String_of_Edge_Group.hip (176.9 KB)

User Avatar
Member
8531 posts
Joined: 7月 2007
Online
you should be able to do just this in Detail wrangle
int pts[] = expandedgegroup(0,'edge_group');
string edge_strings[];
for(int i = 0; i < len(pts); i += 2) {
    append( edge_strings, sprintf("p%d-%d", pts[i], pts[i+1]) );
}

s@edgegroup_string = join(edge_strings, " ");
Edited by tamte - 2023年6月19日 15:47:33
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
56 posts
Joined: 4月 2008
Offline
tamte
you should be able to do just this in Detail wrangle
int pts = expandedgegroup(0,'edge_group');
string edge_strings;
for(int i = 0; i < len(pts); i += 2) {
append( edge_strings, sprintf("p%d-%d", pts, pts) );
}

s@edgegroup_string = join(edge_strings, " ");

Generally,the function “expandedgegroup” is handy and powerful, nice solution, thanks.
User Avatar
Member
1004 posts
Joined: 4月 2017
Offline
Oh, that sounds nice and simple enough. Once I get the time I test it out. Thanks a lot!

-Olivier
  • Quick Links