Accessing attributes from a string

   932   4   1
User Avatar
Member
4 posts
Joined: 5月 2020
Offline
Hello,

I'm trying access the contents of an attribute, using a string to address the attribute. Before anyone suggests using bindings, that isn't an option here and I'll need a way to do it programmatically. In other languages, this is the sort of thing I would do with an eval("@attr1");

I've tried using vertex, attrib, getattrib, and vertexattrib, but none of them work. I know there's something obvious that I'm doing wrong here, but I can't seem to figure it out.

In this simplified test case, I have a polygon box feeding into an attribute wrangle, and the wrangle is running over vertices:

f@attr1 = 5.0;
string attrString = "attr1";
f@attr2 = vertex(0,attrString,@vtxnum);

Any suggestions on how to get this to evaluate?
User Avatar
Member
57 posts
Joined: 7月 2018
Offline
Your simplified test case should work if the f@attr1 = 5.0is first applied to each vertex in its own Vertex Wrangle and then the next Vertex Wrangle can read the attribute using the 2nd and 3rd lines of code just as you've written them.

Attachments:
hou_vertexAttr.PNG (99.8 KB)

User Avatar
Member
4 posts
Joined: 5月 2020
Offline
Thank you for the response. This points to a fundamental concept which I'm not quite understanding in my inexperience. Why can't I apply and then access the @attr1 attribute in the same wrangle?
jsmack
Member
6479 posts
Joined: 9月 2011
Offline
deastman
Why can't I apply and then access the @attr1 attribute in the same wrangle?

The main reason is that the geometry accessed by the code is not the same geometry the code works with, which is a copy.
User Avatar
Member
4 posts
Joined: 5月 2020
Offline
Okay, that’s slightly confusing but I think I understand. Is this explained somewhere in the documentation so I could read more about it?
  • Quick Links