Jump to content

Reverse / Invert Attribute


Recommended Posts

I'm trying to write some vex that takes an input attribute and reverses its values.

I currently need two wrangles. The first to promote the min and max values, the second to invert the attribute:
image.png.9c6f169cbfed9ea1792bf439699d8c1e.pngimage.png.d92c0994b1afad25da221b4fb5b70f3a.png

I wasn't able to directly read the created detail attributes from within the same wrangle that first created the detail attributes. Is this common? Is there another way to read detail attributes that you've just created from within the same wrangle?

 

Hip file attached

promote_min_max.hipnc

Edited by GlennimusPrime
Link to comment
Share on other sites

Thank you @animatrix for the info. I was hoping to keep this within one wrangle.

Another idea I had (unsure if this is possible either).. Instead of writing the min and max values to a detail attribute, is it possible to store a min or max attribute in a similar way as something like this.. I'm guessing here, but:
float dist_max = point(0, "dist", @ptnum, "max");

I realise this is not a real vex command, but what I'm looking for is a way to store that max value to call on again later in the wrangle. I don't have to have it saved as a detail attribute.

Link to comment
Share on other sites

Thanks for the info! I will have to stick with the two wrangles.

I'm always impressed at what people can achieve with just a single wrangle. The want to do everything in just one is strong!

One last thing I would like to try and achieve with this is in the second wrangle. This one simply reverses the distance attribute by re-fitting the original values to the promoted min / max values, like below:
 

//set min and max variable names
float min = detail(0, "`chs("../promote_min_max_dist_to_detail/attribute_name")`_min", 0);
float max = detail(0, "`chs("../promote_min_max_dist_to_detail/attribute_name")`_max", 0);

//invert attribute
f@dist = fit((@dist), min, max, max, min);


In this wrangle, I still need to specify the attribute name 'dist' and also the relative reference path to the node above.
Would there be a way to read the attribute name from the string attribute created in the first wrangle, and also procedurally find the path to the node incoming into input 0 of the second wrangle.

I'm aware of the expression `opinput(".", 0)` to find the name of the input node, but am unsure how to make use of it here.

promote_min_max.hipnc

Edited by GlennimusPrime
Link to comment
Share on other sites

Shouldn't be a problem, I'm not using this on anything that runs over time.

So if I have a string attribute created in the first wrangle like this:
string attribute_name = chs("attribute_name");

How can I access this in the second wrangle, without first knowing the name of the input node or the attribute name?

Link to comment
Share on other sites

Seems like making a problem out of nothing , just make an HDA if you want to reuse it. You can also use attribute promote for that, or you could make a temporary attribute , for example in the begging of chain you rename your incoming attribute to something like "_temp_attrib" and do all of your magic on it , and rename it back to original ( i often do this in assets ) 
Hope this file will make it more clear what i mean 

promote_min_max_edited.hipnc

Link to comment
Share on other sites

3 hours ago, GlennimusPrime said:

Shouldn't be a problem, I'm not using this on anything that runs over time.

It's not just about the time dependency of the node itself but when you use backtick expressions in VEX code, it has to be recompiled every time the expression value changes. You can just do the same using a local parameter using the standard ch* functions and paste your relative parameter reference in that parameter.

Link to comment
Share on other sites

On 5/23/2023 at 2:53 AM, Zunder said:

just make an HDA if you want to reuse it. You can also use attribute promote for that, or you could make a temporary attribute , for example in the begging of chain you rename your incoming attribute to something like "_temp_attrib" and do all of your magic on it , and rename it back to original ( i often do this in assets ) 

I guess I'm just trying to do this with as few nodes as possible. I've used the attribute promote method in the past, but this requires two nodes, one for min, the other for max.
I like the simplicity of a single wrangle. I'm more of a fan of saving vex snippets than building HDAs, I feel like the scene file is easier to share this way too. Thanks for including your example, although I'd still like to try achieve this result with the two wrangles if at all possible.
 

On 5/23/2023 at 3:45 AM, animatrix said:

It's not just about the time dependency of the node itself but when you use backtick expressions in VEX code, it has to be recompiled every time the expression value changes. You can just do the same using a local parameter using the standard ch* functions and paste your relative parameter reference in that parameter.

I never realised this about backtick expressions. Good to know, thanks.

Link to comment
Share on other sites

Still going against your recommendation of using backticks in a wrangle though @animatrix

I'm so close to achieving this in two wrangles - Please see attached hipfile.

I'm only stuck at the very last step. Everything is procedural, right up until the very last line of vex when writing back to the dist attribute.

I have the word 'dist' stored as a detail string attribute, but am not able to use it when writing a float attribute name.
For example I want to write to an attribute called f@dist, but instead of using the word 'dist' I'd like to take that stored string and use it in place of the word 'dist'

like: f@**insert stored string here**

I currently have to explicitly state:
f@dist = fit((@dist), min, max, max, min);

promote_min_max_v02.hipnc

Link to comment
Share on other sites

Thanks @animatrix Do you have an example of this working? I don't see any change when adding this.

This also required the attribute name 'dist' to be known beforehand. I tried to use the detail expression here to read the stored detail attribute called 'dist' but it seems the vex parameter field is unable to read detail strings.

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...