Visibility Tracks and Mapped Functions
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.
8 Comments + Add Comment
Got anything to say? Go ahead and leave a comment!
Want to know about updates the moment they happen? Subscribe to LoneRobot.net
- SliderMan – Does everything that a slider can
- Grabbing The Material Preview
- The Path of the Righteous
- I Don’t Need Regular Expressions
- Kinetic Energy
- What we are today comes from our thoughts of yesterday
- Autodesk Webinar
- Two Clicks From Amsterdam
- WindowBox Replanted
- SpeechBot – A handy script to load and save morpher keys