Jump to content
bonassus

remove prim if point attribute have different values

Recommended Posts

I have a constraint network built with a connectadjacentpieces sop from multiple geometries. Each geometry part has a name with its own naming scheme(Apieces_000, Bpieces_000, etc.).  every primitive in the constraint network has two points each with a name attribute that matches a packed prim with the same name. some of the primitives have points with names from the same geo. These have similar names.

pt0 name=Apieces_000
pt1 name=Apieces_001

some of the primitives have points with names from the different geo And have name attributes with different naming schemes. 

I want to remove the primitives from the constraint network whose points have name attributes from the same scheme by comparing the first character in the name and removing the prim if they are the same. 

 

here's what i have but it'n not working correctly and i don't quite understand the code i've written. 

string name0;
string name1;

i[]@primPts = primpoints(0,@primnum);

foreach(int i; @primPts){
    name0 = point(0,"name",i-1);
    name1 = point(0,"name",i);
    
    if( name0[0] == name1[0] ){
      removeprim(0,@ptnum,1);

    }
   
}

allow me to try and explain. primpoints stores both points from each prim in the primPts array. then it loops through the points and assigns the name attribute of each point to a variable. so far so good i think.

then it compares the first letter of each sting var and if they are the same i want to remove the prim to which the points belong. however this does not happen. 

If someone could point out where I've gone wrong or show me a better way to do this. I would be grateful.  

Thanks

Share this post


Link to post
Share on other sites

it should work with a primitivewrangle with the following code

string s1 = point(0, "name", primpoint(0, @primnum, 0))[0]; //index 0 because you said you wanted to compare the first character
string s2 = point(0, "name", primpoint(0, @primnum, 1))[0];

if(s1 == s2) removeprim(0, @primnum, 1);

 

  • Like 1

Share this post


Link to post
Share on other sites

Thank You Dominik, that help tremendously. I was approaching it in a confusing way.  

 

Although calling the array index with that operator was ambiguous, according to the error message. see attached image.

point(0, "name", primpoint(0, @primnum, 0))[0]

i don't understand why though as i assume the point function is returning a string.

 

however your code works like this. 

string s1 = point(0, "name", primpoint(0, @primnum, 0)); 
string s2 = point(0, "name", primpoint(0, @primnum, 1));

if(s1[0] == s2[0]){
removeprim(0, @primnum, 1);
}

cheers

con3

Edited by bonassus
attachment didn't work the fist time

Share this post


Link to post
Share on other sites

your welcome :)
strange.. was sure I did it like that not long ago at work.. need to double check on monday

anyway, seems like explicitly telling Houdini to return a string from the point() function and then storing that into a string variable works => string s1 = string( point(0, "name", primpoint(0, @primnum, 1)) )[0];
 

 

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

×