Notifications
Clear all

[Closed] Multi/Sub-Map script access??

Hi,
I am writing a script that will set certain colors in a Multi/Sub-Map. However, I can only find a clumsy way of doing this that does not lend itself well to scripting. For example: assuming my Multi/sub-map is stored in a variable called theMat, to set the fourth color I have to actually specify:


theMat.id_4_color = white

But that of course means that I cannot simply set a color by index. I want to be able to loop from 1 to 20 and set each color, but how can I do this if the index is actually part of the name? This is very frustrating, I was expecting an array that I could loop through. Please help. I cannot find a single word about this map in the help, which just adds to the frustration…

3 Replies

Try this:

for val in 1 to 20 do (
	execute ("theMat.id_"+(val as string)+"_color = white")
)

The execute command will evaluate the string as if it is a normal maxscript command.

-Eric

Alternative approach:


 theMap = multi_sub_map() --create a new map
 for theIndex = 0 to 19 do  --loop through the 20 color IDs
 (
 thePropName = "id_" + theIndex as string + "_color" --generate a prop name
 setProperty theMap (thePropName as name) (random black white) --set the color to a random value
 )
 meditMaterials[1]=theMap --load the map in the Medit to see

The reason this is better is that execute expects the variables to be in global scope, so you would have to put both the map and the eventual color value (if stored in a variable) into globals.

thanks Bobo! As always, great advice that works like a charm!

thanks PiXeL_MoNKeY for the idea… that was my work-around at first but as soon as I made it into a macroscript it broke, probably for the globals reason that Bobo listed.