I'm trying to access data stored in a primvar. For a simple test, I'm just trying to get this primvar to show up in the translate y axis of a transform node but I also want to know how to access it in a wrangle node.
Based on another thread, it seems like the following python expression on the y axis parameter should work, and it does compile, but returns 0 when it definitely should not:
If you call `Get()` without an argument, what you get back will be the "default value" of the attribute. If the attribute you are fetching has time samples (or really even if it doesn't have time samples), it's always best to pass a time value to the Get() method. Passing in `hou.frame()` is always a good option but will make your node time dependent. Passing in `0.0` will work if there is a single time sample or if the value is only set as a default value, and will avoid creating a time dependency. But it won't give you the expected result if there are multiple time samples available on the input's stage at the same time.
@mtucker - thank you for your reply. However, I must be misunderstanding something 'cause when I try formulating the "Get()" method as
Get(0.0)
as you suggest. This compiles but still returns "0" instead of the correct value. Perhaps there are multiple time samples available on the input stage as you said that could break it, but I don't think so (I'm really not sure how that condition would arise, actually, but the input is pretty simple). Also, is there really no way to make this work without sampling the time?
I didn't need to put anything in the "Get" method.
Of course, this doesn't answer the question of how to get such attributes in a wrangle, so please chime in if you know how to do that.
Also, if anyone knows how to get a primvar without so much code and without needing to specify the object in the "GetPrimAtPath" method, so that it just uses the input geo, that would be really helpful as well.
Update: if you put "ch("primpattern")" into the "GetPrimAtPath" method, that will use whatever primitive you specify in the "Primitives" field of the node which means you can use `lopinputprims('.', 0)` in the "Primitives" field to get the geo that is plugged into the input.
Here's how you'd grab an element from an array and assign it to a new primvar. You can prob use this to find a way to drive a parm I'd imagine.
vectorvalue = usd_primvarelement(0, @primpath, "displayColor", 3); //Gets the third element in the arrayusd_addprimvar(0, @primpath, "myval", "vector");
usd_setprimvar(0, @primpath, "myval", value);
Hamilton Meathouse vector value = usd_primvarelement(0, @primpath, "displayColor", 3); //Gets the third element in the array usd_addprimvar(0, @primpath, "myval", "vector"); usd_setprimvar(0, @primpath, "myval", value);
That's not python. Is it hscript or vex? I've tried implementing this "usd_addprimvar" as hscript without success. I suspect this is vex meant for use in a wrangle.
... found the doc's for it - yeah, that's vex. This will be useful for when I need to work with a wrangle. Thank you.
Of course, I still haven't found a way to get a value from an array primvar into a parameter. At least not directly. I did come up with a workaround. The attribute I'm trying to access was created in a sopmodify node, so I just split the array into individual float attributes - these I know how to fetch. If you have a pre-existing array primvar whose values you need to fetch, I expect you could push this into a sopmodify node and, there, split the array to individual floats so that they are accessible downstream but... this really shouldn't be necessary.
Here I have a sopcreate that is making a sphere and assigning a random color to each point. Then in the transform lop below it I am adding a python expression in the 'tx' parm that reads a primvar value (in this case displayColor) and sets the 'tz' parm to that value.