Jump to content

Point wrangle - conditional setting of attribs


Recommended Posts

I have a python SOP otl im converting to VEX using the PointWrangle SOP - the OTL processes attribs that may or may not be present; I'd need to keep this behaviour. But.. I noticed that:

 

vector orient;

if(isbound("my_attrib"))
{
    import("my_attrib", orient, 0);
    orient = some_blah(orient);
    v@my_attrib = orient; // CREATES the attrib even if isbound() is false
}
will create @my_attrib, even if it doesnt exist. I tried this:
 
if(isbound("my_attrib"))
{
    import("my_attrib", orient, 0);
    orient = some_blah(orient);
    setpointattrib(geoself(), "my_attrib", @ptnum, orient); // Doesnt create, but doesnt work either
}
 
But, maybe a limitation of PointWrangle, this does nothing.
 
Any other ways of setting this attrib?
Thanks!
Link to comment
Share on other sites

I'm not super expert in vex, but shouldn't you use addattribute instead of setpointattr ?

 

 http://www.sidefx.com/docs/houdini13.0/vex/functions/addattribute 

 

 

EDIT:

i'm not sure what you want to do, but if you want to check if you have an attribute you can use "haspointattrib" function.

 

in a pointWrangle, this works for me.

 

if(haspointattrib(0,"my_attribute"))
{
    addattribute("newAttrib",5);
};
 
 
 
I don't know how to create an attribute in an attributeWrangle.It doesn't seem to recognise  the addattribute function. I can Set an existing attribute but not create one, without using the @ syntax
Edited by MENOZ
Link to comment
Share on other sites

ahh that looks like a much more appropriate function thank you!,.. shame it still doesnt seem to set the value (it does when I use @my_attrib)

 

Ive tried this and this:

addattribute("my_attrib", orient);

addattribute("my_attrib", orient, "type", "vector");

 

so to sum up:

 
This works (but always adds the attrib, even when I dont want it to)
v@my_attrib = orient;
 
This doesnt
addattribute("my_attrib", orient);
 
which seems odd?
Link to comment
Share on other sites

I didn't tried this yet, but to set an attribute you should use a separate function like setpointattrib.

 

http://www.sidefx.com/docs/houdini13.0/vex/functions/setpointattrib

 

 

the reason why @ always is executed is in another thread:

http://www.sidefx.com/index.php?option=com_forum&Itemid=172&page=viewtopic&p=151709#151709

 

hey Adam, I've just read your name, is it you from dneg?

Link to comment
Share on other sites

just to be clear not all VEX function work in all VEX contexts 

so pointwrangle has import(), addattribute() and no setattrib()

attribwrangle has setattrib() functions and no inport(), addattribute()

 

those 2 functions are similar but not equivalent, for your case though they both should do what you want

@ syntax always creates the attribute as it's mapped to export variable, unless you exclude attribute's name from exporting, in that case @ would only read 

 

so if you want to avoid @ syntax

in pointwrangle use:

vector attr = 0;


if ( import("my_attrib", attr, 0) ) 
{
    attr += {1,1,1};
    addattribute("my_attrib", attr); }

for attribwrangle:

vector attr = 0;


if ( haspointattrib(0, "my_attrib") ) 
{
    attr = point(0, "my_attrib", @ptnum) * {2,2,2} + {1,0,0} ;
    setpointattrib(0, "my_attrib", @ptnum, attr, "set"); 
}
 
  • Like 1
Link to comment
Share on other sites

 

in pointwrangle use:

vector attr = 0;


if ( import("my_attrib", attr, 0) ) 
{
    attr += {1,1,1};
    addattribute("my_attrib", attr); }
 

 

 

Thanks Thomas, yes I tried exactly this in PointWrangle but even in a very simple case - literally as you have but a different attrib name, assigning using @ works fine, but with addattribute does nothing.. its odd- I dont see what Im doing wrong - could run this in the VOPSOP instead, but this should work?

 

 

hey Adam, I've just read your name, is it you from dneg?

 

Hey Andrea! Ha yes I should have just waited until tomorrow to ask you about this in rounds, eh?! :P

Link to comment
Share on other sites

ahh great - yes so looks like it was the use of isbound() - I guess that is detecting attribs bound using @ notation rather than being present in the inputs.. all working perfectly with haspointattrib(), import() and addattribute() .. thanks a million!

Edited by adamvanner
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...