Normalized Time

   4004   6   0
User Avatar
Member
10 posts
Joined: Jan. 2017
Offline
I'm building a VEX snippet and I want a way to represent the current frame as a float between 0 and 1, 0 being the first frame and 1 being the frame range. I know that @frame can give me the current frame, but what VEX snippet do I need to get the last frame in my time slider?
User Avatar
Member
2036 posts
Joined: Sept. 2015
Offline
float Frame_Range, New_Value;

Frame_Range = 240;

New_Value = fit(@frame, 0, Frame_Range, 0, 1);
Edited by BabaJ - June 25, 2018 15:24:31
User Avatar
Member
10 posts
Joined: Jan. 2017
Offline
Thank you for the quick reply. This is what I have currently implemented. However, I was wondering if there was a piece of VEX code that would automatically put in the end frame, similar to $FEND when you're working with parameters
User Avatar
Member
2036 posts
Joined: Sept. 2015
Offline
I don't think Vex has direct access to the Frame Range values.

The only way I can think of is to create a parameter and use Python to ‘grab’ your current hip files Frame Range to put it there:

hou.playbar.playbackRange()[1]

playbackRange returns two values, first for the beginning frame range and the second the end, hence the one in square brackets.

Then in vex you could use a channel reference to get that parameter.

Now your saying your building a ‘snippet’ so I assume your inside a vop node, so I don't know if this will work there but it will for a wrangle node at the sop level.

You could use an Hscript reference with backticks.

float End_Frame = `$FEND`;

Edit: on an unrelated sidenote. I was just trying to figure out how to parse the lines of code in a wrangle with python. Looked at the parameter that holds the text, and it too is referred as a snippet.
Edited by BabaJ - June 28, 2018 11:38:20
User Avatar
Member
10 posts
Joined: Jan. 2017
Offline
Thank you! I'll try the backticks method.

I'm using a wrangle node, not a VOP node, so the the text isn't referred to as a snippet in that case?
User Avatar
Member
129 posts
Joined: Oct. 2020
Offline
BabaJ
I don't think Vex has direct access to the Frame Range values.

The only way I can think of is to create a parameter and use Python to 'grab' your current hip files Frame Range to put it there:

hou.playbar.playbackRange()[1]

playbackRange returns two values, first for the beginning frame range and the second the end, hence the one in square brackets.

Then in vex you could use a channel reference to get that parameter.

Now your saying your building a 'snippet' so I assume your inside a vop node, so I don't know if this will work there but it will for a wrangle node at the sop level.

You could use an Hscript reference with backticks.

float End_Frame = `$FEND`;

Edit: on an unrelated sidenote. I was just trying to figure out how to parse the lines of code in a wrangle with python. Looked at the parameter that holds the text, and it too is referred as a snippet.


suprisingly didnt know ou can use python expressions in VEX, I tried this method in a SOP wrangler and it worked, thanks.
https://www.youtube.com/channel/UC4NQi8wpYUbR9wLolfHrZVA [www.youtube.com]
User Avatar
Member
8525 posts
Joined: July 2007
Offline
AhmedHindy
suprisingly didnt know ou can use python expressions in VEX, I tried this method in a SOP wrangler and it worked, thanks.
just to clarify, it's not executing the expression in VEX, any expression in the code parameter is evaluated first and the resulting string in that parameter will get compiled as snippet code
so while injecting constant values like $FEND or $FPS is totally fine, having for example time dependent expression would be very inefficient as it would trigger recompile every time so it's good to be aware of whats happening
Tomas Slancik
FX Supervisor
Method Studios, NY
  • Quick Links