read an attribute name

   804   14   3
User Avatar
Member
43 posts
Joined: 3月 2016
Offline
Hi

I am trying to read an primitive attribute name with an string parameter.

and use that parameter in a wrangler

string maskAttribute = "`chs("../attrMask")`";

it works if put something into the parameter, but if it is empty I get an error message: "Syntax error, unexpected '=', expecting identifier. (30,72)"

how can I avoid it?
there is a "try" command like python, to deal with this kind of error?

Thanks
Edited by Gerardo Castellanos - 2024年4月19日 21:00:07
Gerardo Castellanos
www.gerardocastellanos.com
User Avatar
Member
209 posts
Joined: 1月 2013
Offline
There's no need for backticks or double quotes.

string maskAttribute = chs("../attrMask");
User Avatar
Member
43 posts
Joined: 3月 2016
Offline
alexwheezy
There's no need for backticks or double quotes.

string maskAttribute = chs("../attrMask");

Thanks, but I would like to access to the values of that attribute with a @`chs("../attrMask")`, and I get the same error message when it is empty.
Gerardo Castellanos
www.gerardocastellanos.com
User Avatar
Member
2042 posts
Joined: 9月 2015
Offline
Gerardo Castellanos
Thanks, but I would like to access to the values of that attribute with a @`chs("../attrMask")`, and I get the same error message when it is empty.

What do you mean?
You're accessing a parameter that has only one value and is not bound to anything unless it has been done so intentionally, which if that was the case you could just access the attribute itself.

If you want to create an attribute with that parameter value just do what alex said but instead of a local variable:

s@attrMask = chs("../attrMask");
User Avatar
Member
43 posts
Joined: 3月 2016
Offline
I mean, I want to access to the values of that parameters, not only the name of the attribute.
the field, the paramater could be empty or the user could enter an attribite name.
Edited by Gerardo Castellanos - 2024年4月20日 07:45:45

Attachments:
parameter_attribute_name.JPG (4.5 KB)

Gerardo Castellanos
www.gerardocastellanos.com
User Avatar
Member
2042 posts
Joined: 9月 2015
Offline
Gerardo Castellanos
I mean, I want to access to the values of that parameters,

As alex and I have already shown you can access the value of the parameter with:

chs("../attrMask")

What is entered into that paramater and how you decided to treat it is another matter.

In all cases a string paramter that you are accessing is just that - only a string.

mask_noiser

or it could be:

@mask_noiser

In either case, it's still only a string and you will have to decide how to deal what is entered or not. How it is entered, or not, etc.

Since it's a string and if a 'proper' name is entered, it can be used to pass into a function argument.
If you want to get a point value for example of an attribute specified by your parameter name entered:

int   Result = pointattrib(0,chs("../attrMask"),5);// if attribute specified refers to an integer
float Result = pointattrib(0,chs("../attrMask"),5);// if attribute specified refers to an float
// etc. etc.

If you are wanting to do some general reading of all types of attributes, you are going to have to determine 'class/types' as part of the process.

https://www.sidefx.com/docs/houdini/vex/functions/attribtype.html [www.sidefx.com]
https://www.sidefx.com/docs/houdini/vex/attribtypeinfo_suite.html [www.sidefx.com]

Also, if you or the user entered '@' as part of the parameter text entered, you will have to parse out that symbol character from the string parameter before passing it as a string argument to one of those functions.
Edited by BabaJ - 2024年4月20日 10:50:58
User Avatar
Member
447 posts
Joined: 8月 2019
Offline
Generally speaking, don't use backticks in VEX code. Backticks aren't even a part of VEX syntax: they make the expression between to be evaluated as HScript. They'll make your code more less readable, and potentially introduce time/node dependencies unnecessarily.
User Avatar
Member
101 posts
Joined: 12月 2019
Offline
Gerardo Castellanos
Thanks, but I would like to access to the values of that attribute with a @`chs("../attrMask")`, and I get the same error message when it is empty.

If you are willing to only use @-syntaxe, you would likely need to use bindings :

1. On attribute wrangle > Bindings tab > add one in Number of Bindings > link Attribute Name to your parameter and set the VEX Parameter name


2. In your VEX code, whenever you write @maskAttribute you will be reading/writing the attribute entered by user on the "attrMask" parameter



If it's ok to use other functions like point() and prim() to read attrib value, then it's already covered in previous answers.

Attachments:
bindings.png (50.7 KB)
bindings2.png (75.2 KB)

Houdini Pipeline Supervisor @ TAT Studio
User Avatar
Member
43 posts
Joined: 3月 2016
Offline
@BabaJ, ok, thanks for your answer
@ObeidaZakzak ... ohh good to know, thanks a lot!
Gerardo Castellanos
www.gerardocastellanos.com
User Avatar
Member
768 posts
Joined: 4月 2014
Offline
ObeidaZakzak
Gerardo Castellanos
Thanks, but I would like to access to the values of that attribute with a @`chs("../attrMask")`, and I get the same error message when it is empty.

If you are willing to only use @-syntaxe, you would likely need to use bindings :

1. On attribute wrangle > Bindings tab > add one in Number of Bindings > link Attribute Name to your parameter and set the VEX Parameter name
Image Not Found


2. In your VEX code, whenever you write @maskAttribute you will be reading/writing the attribute entered by user on the "attrMask" parameter
Image Not Found



If it's ok to use other functions like point() and prim() to read attrib value, then it's already covered in previous answers.

If I understand correctly, you can create an parameter; link an attribute to a parameter, instead of as the OP did. Create a string attribute and link the parameter to the function.

I assume the attributeName is always the parameter and the VEX Parameter in bindings is always the attribute ? It's the name of these parameters in the binding that is what I and maybe others just need to have sorted
Edited by _Christopher_ - 2024年4月21日 10:59:39
【T】【C】【S】
User Avatar
Member
4520 posts
Joined: 2月 2012
Offline
Gerardo Castellanos
@BabaJ, ok, thanks for your answer
@ObeidaZakzak ... ohh good to know, thanks a lot!

I also recommend using the Bindings tab if you can, as using any of the point/prim/vertex functions, you will take a severe performance hit over direct attribute binding, even if you are just reading from the current element.

A lot of people in production are not aware of this.
Senior FX TD @ Industrial Light & Magic
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com]

youtube.com/@pragmaticvfx | patreon.com/animatrix | pragmaticvfx.gumroad.com
User Avatar
Member
209 posts
Joined: 1月 2013
Offline
animatrix_
Gerardo Castellanos
@BabaJ, ok, thanks for your answer
@ObeidaZakzak ... ohh good to know, thanks a lot!

I also recommend using the Bindings tab if you can, as using any of the point/prim/vertex functions, you will take a severe performance hit over direct attribute binding, even if you are just reading from the current element.

A lot of people in production are not aware of this.

I've never done performance tests for this, but how much slower is it? I think few people know about this feature because few people talk about it at all in their lessons. It is easier for artists to call the appropriate function.
User Avatar
Member
768 posts
Joined: 4月 2014
Offline
I wasn't aware of this either bindings tab of the wrangler nodes. Then again from the screen shot, and recent versions of Houdini, the name has changed as it's now; Evaluation Node Path & Export Parameters.

Although some may find this naming a bit easier to understand then the screen shot posted here as to whatever version of Houdini that maybe; https://www.sidefx.com/forum/topic/95575/#post-420226 [www.sidefx.com] it still may be a mystery to some. Evaluation node path can't be the parameter to which you want to bind the attribute too unless you can't choose a parameter from another node ?

Following Export Parameter is the parameter which you want to bind the attribute too, do I have this understood ?

Although it is news to me that it is faster then using functions, then again; I always wanted to know the point of this tab.
【T】【C】【S】
User Avatar
Member
4520 posts
Joined: 2月 2012
Offline
alexwheezy
I've never done performance tests for this, but how much slower is it?

It depends on the input geometry, i.e. number of elements but from my tests with high res geo (10M+ points), it was orders of magnitude slower because the point/prim/vertex functions are designed to look up arbitrary elements.

alexwheezy
I think few people know about this feature because few people talk about it at all in their lessons. It is easier for artists to call the appropriate function.

That's why I talk about all kinds of tricks like this in Pragmatic VEX
Senior FX TD @ Industrial Light & Magic
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com]

youtube.com/@pragmaticvfx | patreon.com/animatrix | pragmaticvfx.gumroad.com
User Avatar
Member
768 posts
Joined: 4月 2014
Offline
animatrix_
alexwheezy
I've never done performance tests for this, but how much slower is it?

It depends on the input geometry, i.e. number of elements but from my tests with high res geo (10M+ points), it was orders of magnitude slower because the point/prim/vertex functions are designed to look up arbitrary elements.

alexwheezy
I think few people know about this feature because few people talk about it at all in their lessons. It is easier for artists to call the appropriate function.

That's why I talk about all kinds of tricks like this in Pragmatic VEX

Watch your videos to learn this & more
【T】【C】【S】
  • Quick Links