Visibility Tracks and Mapped Functions

Jan 14, 2009 by     8 Comments    Posted under: 3dsMax, Maxscript

Some methods are useful and can get overlooked when perusing the MXS help. For me, one of them is the use of a mapped function in maxscript.

Mapped functions act in the same way as a normal function but instead of manually specifying a loop for each element of an array or collection, the loop is performed automatically when a collection or array of values is passed as the first argument of a function.

There is still nothing wrong with performing a function on each element in turn, (and I frequently do), but I wanted to highlight this as an option that can added to the scripting toolkit.

The example is used in this visibility script. I needed something that i could set the object visibility quickly without having to open the curve editor each time. Therefore, if an object did not have a visibility track, it should be added.

 

 

 

mapped fn setviskey objs visval intan outtan =
(
if (getVisController objs) == undefined do VisibilityAssistant.adddviscontroller objs
local tvis = objs.visibility.controller
addnewkey tvis currenttime
keyind = getKeyIndex tvis currenttime
tvis.keys[keyind].value = visval
tvis.keys[keyind].inTangentType = intan
tvis.keys[keyind].outTangentType = outtan
)

The mapped function is passed the objs array (via selection as array) and then loops through each element. There is no need to specify a for/loop.

In theory this should be more efficient and faster, but for something like this it really doesnt make any difference.

The other thing of mild interest in the script is a custom trackbar filter. It allows you to only see visibility keys on the trackbar. Feel free to look through the code. You’ll also see the script is contained within a Struct. This allows you to specify one global variable and call many methods from it, including the rollout creation.

download mapped functions script

8 Comments + Add Comment

  • avatar

    Thanks you so much for this script. This is amazingly simple and I still cant believe Max make this powerful track so cumbersome and difficult to use within the interface. thank you so much

  • avatar

    Thank youi very much for this!
    How can they not do something like this from max kinectic days!

    Cheers!

  • avatar

    Hi LoneRobot, very handy script, but is there a way expand your script with a read out of the visibility value of the selected object(s)? Greetz Nino

  • avatar

    Wow thanks for the script , really appreciate your contribution.

  • avatar

    Thanks for your comment, brot

  • avatar

    This simplified some animation for me a lot, thanks! Nice UI layout btw

  • avatar

    Thanks for your comments, Paul, I hope you can learn some small tips and tricks from the tutorials on here.

  • avatar

    It looks useful. I think the choices to step is a real good idea. I use one from Mar troy but it does not have what you have.
    I wish I had your Ability with script.
    Thanks from
    Paul.

Got anything to say? Go ahead and leave a comment!

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>