PDA

View Full Version : How the heck do you....


jpn5
12-26-2008, 02:35 PM
Hi guys I'm trying to create a maxscript code that will allow me to animate the colour of a light...

I have a whole bunch of questions with being new to Maxscripting but before i can even begin testing my script i need to assign rgb color values to the items in my listbox (so that when a color name is selected- it will assign a rgb value to the light).

so I have


listBox presetLst ""
items:#
(
"Warm White",
"Neutral White",
"Cool Blue",
"Pale Blue"
)

... and then elsewhere in my script i have the following:

on btnAply pressed do
(
if(selection.count > 0)then
(
for obj in selection do
animate on
(
for i = 0 to 100 by 50 do
(
at time i $.color = presetLst.selection
)
)
)
)
else
(
messageBox "you must have at least one object selected!"
)

So when i evaluate the script it tells me:

"- Unable to convert: 1 to type: Color"

Just wondered if anyone can tell me where abouts and how i would difine the values of the items in my listbox?

i.e
"Warm White" is 255 255 228
"Neutral White" is 255 255 255
"Cool blue" is 169 205 249
"Pale Blue" is 208 226 249

Thanks very much.

Jpn5

JHN
12-27-2008, 02:05 PM
I think .selection returns the selected index index as integer, you'd probably need .selected from the listbox, that will return the string. But the string won't help either since maxscript only supports

red
green
blue
white
black
orange
yellow
brown
gray

as color literals, so you'll need some lookup table to figure out color values by their literals.
I'd go for a array of structs which hold the color literals and values for example:



(
-- Struct to use as color "LUT"
struct sColor ( name,value )
-- Array to store colors
colorArray = #()

-- Append colors here
append colorArray (sColor "Warm White" (color 255 255 228))
append colorArray (sColor "Neutral White" (color 255 255 255))
append colorArray (sColor "Cool blue" (color 169 205 249))
append colorArray (sColor "Pale Blue" (color 208 226 249))

-- Some logic to work with
searchName = "Cool blue"
for c in colorArray where c.name == searchName do print c.value
)


Hope this helps,
-Johan

jpn5
12-29-2008, 10:41 PM
Johan, thank you for your reply I haven't got round to trying it yet but i hope to tomorrow, I'll let you know how i get on!
Thanks again.


JPN5

JHN
01-03-2009, 07:34 PM
Ok here's an example from the question you pm'ed me.
I did made my own rollout though!


rollout colors "myColors" width:160
(
-- ROLLOUT LOGIC

-- Array to store colors
local colorArray = #()

-- Build initial color list
fn buildColorList =
(
-- Struct to use as color "LUT"
struct sColor ( name,value )

-- Manually append colors here
append colorArray (sColor "Warm White" (color 255 255 228))
append colorArray (sColor "Neutral White" (color 255 255 255))
append colorArray (sColor "Cool White" (color 169 205 249))
append colorArray (sColor "Pale Blue" (color 208 226 249))
/* ... etc add more colors */

)

-- UI ITEMS
listBox presetLst "" width:150 align:#center
button apply "Apply Color" width:150 align:#center

-- EVENT HANDLERS
on colors open do
(
-- Init the colors
buildColorList()

-- Build the color list in the listBox
presetLst.items = for c in colorArray collect c.name

)

on apply pressed do
(
-- Find the color in the array and print it's color, returns an array(!)
local theColor = for c in colorArray where c.name == presetLst.selected collect c.value
-- Loop over the lights find the ones that are selected
for l in lights where l.isSelected do
with animate on
l.color = theColor[1] -- apply the color, we pick the first item because theColor was an array(!)

)
)

createDialog colors


I hope you can work with it!

Goodluck and let us know how it worked out

-Johan

jpn5
01-06-2009, 10:06 PM
Awesome, Thanks for your help on that Johan... Think my biggest problem with Ms is knowing what order to put things into the script.

Take it easy

JPN5

CGTalk Moderation
01-06-2009, 10:06 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.