How do I Create a Button to Show the Next Object?

new.gif MAXScript Frequently Asked Questions

A user asked:

I want to create a button that shows only one object at a time, hiding all others. When I press it multiple times, it should loop through the scene objects showing me the next one.

Answer:

Here is a possible solution:

Script:

macroScript showNext category:"MXS Help"

(

local current_object = 0 --this is local to the macroScript

on execute do

(

allObjects = objects as arraycollect all objects

hide $* --hide all objects

current_object += 1 --increment the counter

if current_object > allObjects.count doloop if necessary

current_object = 1

if allObjects.count > 0 do --if anything in the scene...

unhide allObjects[current_object]

-- then unhide the current object

)

And this is the same script, but changed to show objects in alphabetical order:

Script:

macroScript showNextABC category:"MXS Help"

(

local current_object = 0 --this is local to the macroScript

on execute do

(

-- collect all names and sort them:

allObjectNames = sort( for i in objects collect i.name )

hide $* --hide all objects

current_object += 1 --increment counter

if current_object > allObjectNames.count do --loop if necessary

current_object = 1

if allObjectNames.count > 0 do --if anything in the scene...

unhide getNodeByName allObjectNames[current_object]

-- then get the object by name and unhide it

)

 

See also

Frequently Asked Questions