How to pass VEX variable type to a function

   3768   4   1
User Avatar
Member
2038 posts
Joined: Sept. 2015
Offline
Hello,

I was wondering if anyone knew how to pass a vex variable type to a function, in my particular case I am trying to

pass an @group_mygroup

Documentation says it's an int so in my function I declare the argument as an int, but I keep getting segmentation fault and houdini crashes when I try to use @group_mygroup in the functions argument.

I know I could just do the operation intended with the @group_* type and pass it's result to a variable that can then be passed to the function, but I am trying to see if I can do that operation within the function itself leaving any pre-function not necessary.

I'm guessing too that vex types are not quite the same as tyical types like int, float, etc. and maybe user defined functions simply cannot be setup to incorporate them?

Unless they need some special pre-pending when passed as an argument? It's a slow process to test that when the program keeps crashing.


Any insight is appreciated, thanks.

Edited by BabaJ - Aug. 31, 2016 09:17:42
User Avatar
Member
604 posts
Joined: July 2013
Online
Is there a reason you're wanting to pass the attribute to the function instead of simply reading the attribute inside the function definition?

In a Wrangle, Attributes are Global to the Wrangle, so they dont need to be passed, as they will always be in scope.
Edited by TwinSnakes007 - Aug. 31, 2016 17:05:06
Houdini Indie
Karma/Redshift 3D
User Avatar
Member
2038 posts
Joined: Sept. 2015
Offline
Sorry Daryl…I'm not sure what you mean.

To me “@group_*” is not an attribute…it's a type from which different vex function can be applied to/worked with, one of which would be to get attributes from the “@group_*”.

That's the reason I want to know how to pass it to my function.

So that within my function I have to option of applying the different vex functions depending on my needs.

At the moment I have to “extract” or apply the desired vex function to “@group_*” before passing it to my function.

It's more of an idea to be able to keep my code more simplified in ( currenlty using point wrangling ) the vex code window.

All my user defined functions are in *.h files which I include as header files in the point wrangling.

Additionaly, it's not really a “problem” since at the moment I have taken a different approach which works with no problems.

I just see a potential to structure my code in a much more larger and more easily workable manner if what I was aiming to do is possible.

Thanks for taking to time to chime in.
User Avatar
Member
604 posts
Joined: July 2013
Online
All data in Houdini is an attribute, that's the whole point of the Network graph, IMO.

Here is the definition for the “@group_*” attribute..

A special virtual attribute of the form @group_groupname lets you get or set group membership for the current element.

It is a per-element int whose value will always either be 0 or 1.

To access or declare an element group in vex, you have to prefix the groupname with “@group_”, i.e., @group_groupname. This syntax is literal, meaning, groupname cannot be a calculation of any kind or a pattern.

Having said that, I think my point is still valid. If your functions are consuming/producing a group attribute, you dont need to pass those groups to your functions, you can access them directly in your functions and add some safety checks to see if the groups you are expecting to exist, actually exist on the objects your functions are operating on.
Houdini Indie
Karma/Redshift 3D
User Avatar
Member
2038 posts
Joined: Sept. 2015
Offline
Hi Daryl,

Ok, I see what your saying now.

So, in my case using the “@group_*” element won't work if I use it directly in my functions.

The reason is that the function becomes non-resuable, meaning if I want another point wrangle node to use that function with a different group named by @group_ then I have to have another function written out with the different name after @group_

And I am using many ‘different’ point wranglers working on different sets of groups. But all use the same one function; Amongst combination of other functions.

The way I have it set up now is that I only need to have the one defined function that all those differently set up point wranglers can use. All I need to do is change the arguments accordingly.

In some of those arguments the function needs I am using strings like:

“op:name_of_the_node_containing_specific_group”

The string changing reflecting which group I want that function to work on.

It is these string arguments that I wish to replace with the @group_ element.

Without elaborating, it would make it easier to read the code if I am looking at the arguments of my function and see the name of the group instead of the name of the node, especially when that node may contain more than one group.

  • Quick Links