Trying to change "RGB color space" parameter in Vraybitmap using Maxscript


#1

Hi, I’m day 1 newbie in maxscript.
I’m using 3ds max 2022 and trying to automate change RGB color space of Vraybitmap in my scene.


I have tested a line I found on chaos forum :
for m in (getclassinstances vraybitmap) do m.rgbColorSpace = 1

It works for me, turning every vraybitmap’s rgbColorSpace in the scene to sRGB.

Then I want to achieve something with more function.

  1. I want to only change the rgbColorSpace of diffuse map of vraymtl respectively, I don’t want to change bump map, normal map or other map.
  2. I want to know how to change only the diffuse map of selected object’s material / only the diffuse map of selected material inside slate material editor.

The following is what I have tried, but failed…

for m in (getClassInstances vraybitmap) do
(
if isKindOf m.texmap_diffuse Bitmaptexture then
(
do m.rgbColorSpace = 1
)
)

Then Max script listener return me : – Syntax error: at ), expected


If somebody can guide me how to achieve the function I need :
How to change only the rgbColorSpace of diffuse map but not all vraybitmap in the scene.
How to limit the target to selected object’s material / current selected material inside slate material editor

And if it can be write in the form similar to the format I have tried would be great, thanks in advance.


#2

each render engine has its own set of materials and ‘diffuse’ slot property named differently across materials
what you want isn’t something unique, try googling older answers posted on this forum

you’ll have to decide what to do with maps that are connected to both diffuse & bump, etc slots


#3

I have searched the way it works of 3ds max bitmap, but in search of vraybitmap, well atleast at this forum, I didn’t get much information.

I don’t know the exaxt diffuse slot “property name” in vraymtl, I kind of think that’s the last key part blocking my simple script to function.

My idea is simple : any vraybitmap that have been put in diffuse slot, change it’s RGB color space, no other condition. (although this concept might be wrong.)


#4

show (vraymtl()) will show all the properties of the vray material, including the diffuse texmap.
You need to find all the instances of vray material, check whether the diffuse texmap is not undefined, and, is of class that you want, and etc., and then change the properties that you want.


#5

Hi, I have tried

and the only one I found that could be the right one is : .texmap_diffuse

so I try


for m in (getClassInstances vraybitmap) do
(
if isKindOf m.texmap_diffuse then
(
do m.rgbColorSpace = 1
)
)


but no luck :sweat: still return – Syntax error: at ), expected


#6

try what har1sf0x suggested


#7

Hi, I do tried what har1sf0x suggested.

show (vraymtl()) to get those parameter related to vraymtl.
And then the only thing I found that could be the right one is .texmap_diffuse

And check whether the diffuse texmap is not undefined — since I’m totally new to maxscript, I have no idea what’s the keyword to check what is defined and what is not, or how do I define it.

I have used the information I got so far to tweak and test the maxcript, if you have additional tips would be great.


#8

har1sf0x was talking bout smth like this

for mtl in getclassinstances vraymtl where mtl.texmap_diffuse != undefined and iskindof mtl.texmap_diffuse vraybitmap do mtl.texmap_diffuse.rgbColorSpace  = 1

#9

Thanks to you and har1sf0x’s guide, the script is working.

There is a final function I want to achieve, that is to only work on the object I select.
I have search some post that about runing script on selected object, and it seems those script work for them,
but when I adding into the script I’m trying to build as following :

objs = getCurrentSelection()
for obj in objs do
(
for mtl in getclassinstances vraymtl target:obj where mtl.texmap_diffuse != undefined and iskindof mtl.texmap_diffuse vraybitmap do mtl.texmap_diffuse.rgbColorSpace=1
)

3ds max listener return me with the error :

-- Syntax error: at ), expected <factor>
--  In line: )

Any tips how to fix this?