Showing posts with label delete. Show all posts
Showing posts with label delete. Show all posts

Friday, 10 April 2026

how to match geo based on path attribute and delete non matching (or keep) primitives

This is quite a specific script.. I got chatgpt to make them for me!

TWO SCRIPTS - they compare input 0 and 1's path attritbutes. Firstly, they strip away (deleting) the primitives that don't match. 
Use case-  you have two mostly identical alembic files of a house. One has UVs you want to transfer to another, but maybe one has some excess geo that you haven't processed yet, or forgot to delete. This will get the two alembics having the same geo (based on path attributes!), so you could do a clean transfer.

 // Get this primitive's path

string my_path = prim(0, "path", @primnum);


// Flag to track match

int match_found = 0;


// Loop over all primitives in input 1

int nprims1 = nprimitives(1);

for (int i = 0; i < nprims1; i++)

{

    string other_path = prim(1, "path", i);

    

    if (my_path == other_path)

    {

        match_found = 1;

        break;

    }

}


// Remove primitive if no match

if (!match_found)

{

    removeprim(0, @primnum, 1); // 1 = delete associated points if unused

}



AND THE REVERSE - KEEPING ONLY THE NON MATCHING STUFF, so you can merge that back into the matching stuff after transferring UVs or whatever.



// Get this primitive's path

string my_path = prim(0, "path", @primnum);


// Flag to track match

int match_found = 0;


// Loop over all primitives in input 1

int nprims1 = nprimitives(1);

for (int i = 0; i < nprims1; i++)

{

    string other_path = prim(1, "path", i);

    

    if (my_path == other_path)

    {

        match_found = 1;

        break;

    }

}


// Remove primitive if a match IS found (reverse logic)

if (match_found)

{

    removeprim(0, @primnum, 1);

}

replacing strings

can't remember if i've written about the "Replace" function. Replacing a given string with nothing, eg "" is a *another* way to remove parts of an existing string!


string tempo=s@path;

tempo=replace(tempo, "/ppHeroBuilding_forTexture/","");

@path=tempo;