Notifications
Clear all

[Closed] Equivalent of Maya's min() & max()?

Anything like Maya’s MEL min() & max() functions exist in maxscript?
If unfamiliar with them, min() & max() return the small of two numbers (min) or the larger of two numbers (max).

I can obviously write the simple function to do the same thing, but I’m just wondering if it already exists somewhere and I just missed it.

Thanks,

Alec

3 Replies
1 Reply
(@bobo)
Joined: 11 months ago

Posts: 0

The equivalent in MAXScript is amin() and amax(). The ‘a’ is for ‘array’ and you pass the values to test as array. The result is the min or max value of all values in the array.

For example,

amin #(10,20.3,1.1,15)
--> 1.1
amax #(10,20.3,1.1,15)
--> 20.3

The beauty of this method is that it works on any array whose values can be compared.
For example

amin #("bobo","test","ah!","oh!")
-->"ah!"
amax #("bobo","test","ah!","oh!")
-->"test"

which is equivalent to

theArray = #("bobo","test","ah!","oh!")
(sort theArray)[1]
(sort theArray)[theArray.count]

Cool. Slightly embarrassing it was right there.
Thanks for the help.

What about an equivalent for linstep and smoothstep?

Thanks again,

Alec

Just a note, you can also do something like

amin 0 10
0
amax 0 10
10

so you could combine both methods to ‘clamp’ a number (eg. between -4 and 13):

myVal = 16
16
myVal = amax -4 (amin 13 myVal)
13
myVal = -50
16
myVal = amax -4 (amin 13 myVal)
-4

Cheers,
Martijn