Merge Curve Prim if they have the same prim attributes

   782   0   0
User Avatar
Member
2 posts
Joined: Jan. 2018
Offline
//find Neightbors Prim
int prims[];
int pts[] = primpoints(0,@primnum);
foreach (int pt; pts)
{
    int pt_prims[] = pointprims(0,pt);
    if(len(pt_prims)>1)
    {
        foreach (int pt_prim; pt_prims)
        {
            if(pt_prim != @primnum)
                append(prims,pt_prim);
        }
    }
}

//Get Prim Attribute Names
string attrs[] = detailintrinsic(0,"primitiveattributes");

//Check Neighbors prim if they are Valid, Append to the "set"array
i[]@set;
append(@set,@primnum);

foreach (int prim; prims)
{
    int valid = 1;
    foreach (string attr; attrs)
    {
        int type = primattribtype(0,attr);
        if ( type == 0 ) 
        {
            //Ignore ID and Primnum, do not check
            if( attr == "prim_num" || attr == "id" )
                break;
            // Check if not the same attribute, make unvalid
            int val1 = prim(0,attr,@primnum);
            int val2 = prim(0,attr,prim);
            if ( val1 != val2 )
            {
                valid = 0;
                break;
            }
        }
    }
    if( valid == 1)
    {
        append(i@set,prim);
    }
}

foreach(int prim;i@set)
{
    string name = "G" + itoa(@primnum);
    setprimgroup(0,name,prim,1,"set");
}

the attachment is a test curve with serveral prims i need to merge if all the prim int attribute is the same(not included id and prim_num). i am almost there but dont know how to finish it....
thank you
Edited by WongChunNga - April 7, 2022 06:13:29

Attachments:
test.bgeo.sc (24.1 KB)

  • Quick Links