View Full Version : Accessing Submaterials with Gradientramp

06 June 2008, 01:25 PM
Hello, I'm slightly confused by the MaxScript access of materials.
I'm having a GradientRamp in which Flag3 has a AVI assigned.
There I want to change the starttime, but it doesn't work as
simply as my mind is:

meditMaterials[1].diffusemap.gradient_ramp.flag__3.starttime = 30f

If anybody has some scripts showing how to access sub-materials
and nested maps effectivly I would be very happy. My usual
approach of using the MacroRecorder for "understanding Maxscript"
doesn't help much, since the recorded infos aren't usable as
a script in a direct way ...

Thanks, Rob

06 June 2008, 04:36 PM
If you apply a noise texture to the middle flag of the gradient and execute the following in the Listener:
show meditMaterials[1].diffusemap.gradient_ramp.flag__3

-- it should return something like this:
.Color : point3
.Position : float
So the texture map can be accessed like so:
As you can imagine, changing the texture of this flag to something else will break your script since the property name will also change. So, instead of using properties, you could access the bitmap through the flag's subanims structure (the textureMap is at index 6):
meditMaterials[1].diffusemap.gradient_ramp.flag__3[6].starttime = 30f
Same goes for the flags themselves. Renaming the flag will also cause the property name (.__flag3) to change. So instead use the gradient ramp's subanim structure to retrieve the flag (3rd flag is at index 4):
meditMaterials[1].diffusemap.gradient_ramp[4][6].starttime = 30f

Hope this helps,

06 June 2008, 08:01 AM
Thanks a million Martijn!

That really helps me a lot, but as for the index of "[6]"
for bitmap, how is this defined? I looked for details
of the SubAnim structure of GradientRamp in the
documentation on that issue and it's general definition
and had no success...

And as I said, if you can recommend a script using
all these sub-texture operations? I would like to see
it to understand the whole process better.

Best, Rob

PS: I would like to assign textures to flags via script and
it always says "No put function for SubAnim:Flag"...

06 June 2008, 03:14 PM
The MacroRecorder safes the following:

meditMaterials[1][#Maps][#Diffuse_Color__Map__1____Gradient_Ramp].Flag__3__Texture = Bitmaptexture fileName:"c:\bla.ifl"

And using this as a Script base, I get an "Error occurred in anonymous codeblock",
"Unknown property: "Flag__3__Texture" in SubAnim:

I wished the MaxScript documentation would feature some more
Material/Texture samples... Rob

06 June 2008, 06:43 PM
Unfortunately, you cannot rely on anything the macro recorder spits out. It will work for simple commands, but that's about it. The reason behind this has been explained in several other threads so I won't get into details.

Back to your question. As far as I know, you cannot assign textures to flags using mxs. You could replace an existing texture (see below), but this will not work if the flag didn't have a texture assigned to it in the first place.
replaceInstances meditMaterials[1].diffuseMap.Gradient_Ramp[4][6] (noise())
As for your question about subanims, I'd recommend reading the topic in the mxs reference (topic "Subanims"). Here's a quick summery taken from that topic:
As an alternative to using named property accesses, you can access in an object any animatable property that is visible as a track in Track View by indexing the 3ds Max object value as though it were an array. This simplifies such tasks as iterating over all the animatable properties in an object and accessing sub-controllers that don't have unique names, such as within list controllers.
Hope that helps,

06 June 2008, 07:33 PM
Thanks Martijn, this helps a lot (again). So I'll set up a base material
and use scripts only to change values / maps. That's fine, just
thought this could be done more elegantly...

Best, Rob :)

06 June 2008, 08:24 PM
On a side note, the following:
replaceInstances meditMaterials[1].diffuseMap.Gradient_Ramp[4][6] (noise())
will replace all instances of the texturemap. So if you're using the same texture (instanced) somewhere else in the scene, that texture will be replaced as well.


06 June 2008, 11:49 AM
I generated an array of maps with the same IFL sequence but
different starttimes. Then I use replaceInstances and (of course)
all of these get unified...

Is there a possibility to apply them without ALL instances replaced?

Thanks, Rob

06 June 2008, 01:40 PM
Other than using replaceInstances, I don't think there's a way to replace a flag's texture. So all gradient maps and the textures applied to the flag need to be unique for this to work..

06 June 2008, 03:22 PM
Thanks, so what would be an efficient way to create lots of
maps consiting of the same Bitmap but with unique names
that then could be linked afterwards?

I still haven't understood how Max handles names of Maps,
especially when I want to access them array-like...

Thanks, Rob

06 June 2008, 09:55 AM
I'm using a assignNewMaterial now to make the textures unqiue,
but it's still completely replaced by replaceInstances :(

Thanks, Rob

CGTalk Moderation
06 June 2008, 09:55 AM
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.