GlennimusPrime Posted May 18, 2023 Share Posted May 18, 2023 (edited) 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: 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 May 18, 2023 by GlennimusPrime Quote Link to comment Share on other sites More sharing options...
animatrix Posted May 18, 2023 Share Posted May 18, 2023 Yes that's how it is. You can't read the attributes you just created within the same wrangle. Quote Link to comment Share on other sites More sharing options...
GlennimusPrime Posted May 18, 2023 Author Share Posted May 18, 2023 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. Quote Link to comment Share on other sites More sharing options...
animatrix Posted May 18, 2023 Share Posted May 18, 2023 The only way you can do that is by using a Detail Wrangle, then you can get the min and max in the same wrangle but the performance will suffer. Quote Link to comment Share on other sites More sharing options...
GlennimusPrime Posted May 21, 2023 Author Share Posted May 21, 2023 (edited) 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 May 21, 2023 by GlennimusPrime Quote Link to comment Share on other sites More sharing options...
animatrix Posted May 22, 2023 Share Posted May 22, 2023 You can store the attribute name in another attribute. Using backticks inside VEX code is a very bad idea also. It will cause re-compilation and take a performance hit every time this happens. Quote Link to comment Share on other sites More sharing options...
GlennimusPrime Posted May 22, 2023 Author Share Posted May 22, 2023 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? Quote Link to comment Share on other sites More sharing options...
Zunder Posted May 22, 2023 Share Posted May 22, 2023 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 Quote Link to comment Share on other sites More sharing options...
animatrix Posted May 22, 2023 Share Posted May 22, 2023 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. Quote Link to comment Share on other sites More sharing options...
GlennimusPrime Posted May 24, 2023 Author Share Posted May 24, 2023 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. Quote Link to comment Share on other sites More sharing options...
GlennimusPrime Posted May 24, 2023 Author Share Posted May 24, 2023 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 Quote Link to comment Share on other sites More sharing options...
animatrix Posted May 24, 2023 Share Posted May 24, 2023 You can do it like this: Quote Link to comment Share on other sites More sharing options...
GlennimusPrime Posted May 24, 2023 Author Share Posted May 24, 2023 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.