Categories
Blog Max Script Visual Effects

Max Script

well, my first attempt, first serious attempt i guess at doing some max script. was pretty tough but i did do some programming back some time ago, it’s probably a good time to pick it up again.

anywhere so here’s a simple script that displays light information in the viewport. stlil a work in progress of course.

global SetDisplayLight_Rollout
global LightDisplayColor= red
global DisplayData = #(true,false,false,false)

try (destroyDialog SetDisplayLight_Rollout)catch()

unregisterRedrawViewsCallback DisplayLights

fn DisplayLights =
(
gw.setTransform(matrix3 1)

for o in lights where not o.isHidden do
(
LightProperties = “”
if DisplayData[1] then
(
LightProperties += o.name
)
else
(
LightProperties+= “”
)

if DisplayData[2] then
(

if o.enabled then
LightOn = “Light On”
else
(
LightOn= “Light Off”
)

LightProperties += (” “+ LightOn)
)
else
(
LightProperties+= “”
)

if DisplayData[3] then
(

if o.baseObject.castShadows then
LightShadow = “Casting Shadow”
else
(
LightShadow = “No Shadow”
)

LightProperties += (” “+ LightShadow)
)
else
(
LightProperties+= “”
)

if DisplayData[4] then
(
if o.baseObject.castShadows then
LightProperties += (” ” + (o.shadowGenerator as string))
else
(
LightProperties+=””
)

)

gw.text o.pos (LightProperties as string) color:LightDisplayColor
)

gw.enlargeUpdateRect #whole
gw.updateScreen()
)–end fn

rollout SetDisplayLight_Rollout “Light Display Color”
(

radiobuttons onOrOff labels:#(“On”, “Off”)

on onOrOff changed state do
(
print (onOrOff.state)
if onOrOff.state == 1 then
(
unregisterRedrawViewsCallback DisplayLights
DisplayLights ()
registerRedrawViewsCallback DisplayLights
max views redraw

)
else
(
unregisterRedrawViewsCallback DisplayLights
max views redraw
)
)

checkbox LightName “Light’s Name” checked:true
checkbox LightState “Light on or off”
checkbox LightShadow “Shadows”
checkbox LightShadowType “Shadow Type” enabled: false

on LightName changed theState do
(
DisplayData [1] = LightName.state
max views redraw
)

on LightState changed theState do
(
DisplayData [2] = LightState.state
max views redraw
)

on LightShadow changed theState do
(
DisplayData [3] = LightShadow.state
LightShadowType.enabled = LightShadow.state
max views redraw
)

on LightShadowType changed theState do
(
DisplayData [4] = LightShadowType.state
max views redraw
)

dropdownlist SelectColor “Display Color” items:#(“red”,”white”,”blue”,”black”,”yellow”)

on SelectColor selected i do
(
if SelectColor.items[i]==”red” then (LightDisplayColor= red ;max views redraw)
if SelectColor.items[i]==”white” then (LightDisplayColor= white ;max views redraw)
if SelectColor.items[i]==”blue” then (LightDisplayColor= blue ;max views redraw)
if SelectColor.items[i]==”black” then (LightDisplayColor= black ;max views redraw)
if SelectColor.items[i]==”yellow” then (LightDisplayColor=yellow ;max views redraw)
–print (LightDisplayColor)
)

button CloseIt “Close”
on CloseIt pressed do
(
unregisterRedrawViewsCallback DisplayLights
max views redraw
try (destroyDialog SetDisplayLight_Rollout)catch()
)
)
createDialog SetDisplayLight_Rollout 150 180

screenshot of the script at work