Determine if time is outside timesamples

Hello!
I was wondering what the best method for testing if a time is outside the values authored on an attribute. For example, if I’m querying the name on a render product and it’s authored only up to frame 200, if I query 300, I get the file name for 200. But, I’d rather get None or some way to know I’m outside the range authored. I was going to do something like:

min(prop.GetTimeSamples()) <= current_time <= max(prop.GetTimeSamples())

But was wondering if there was a better way? Thank you!

You definitely want to cache the call to GetTimeSamples(), because it may entail a mathematical time transformation of each sample-time in the originating layer (or even more significant computation in the case of Value Clips), because USD allows each reference, payload, and subLayer arc to scale and shift the times of samples in the “referenced” layerStack.

If you are concerned about having alot of timeSamples, what you could do instead is call GetBracketingTimeSamples() twice, once with -inf, and once with inf, which will return you the properly-transformed times of the first and last timeSamples for the attribute. When there are many samples, that will likely be significantly faster.

1 Like

Thank you! In this particular case I’m not too worried about a lot of time samples (I’m querying the render product to run some post processing on the frames rendered and want to eliminate human error specifying frames outside the range) But it is good to know the most efficient methods in case I need to do this on other properties. I’ll still cache the call to GetTimeSamples though :slight_smile: