Help modify script to colorcorrect a bunch of VRayMtl or 2Sided in Multimat

Hi there,

I tried it the last to days to get it done by myself. Just startet learning scripting last weeks. I'm clueless now.

I need a script that assigns a CC to VRayMtl or 2Sided where I can set the hueshift,tint and so on. It also should check if there is already an color correct and then change its values.

I took an existing script and change it to VRayMtl. Works
But if I neeed to change the shift and hue a second time the script creates a second CC. I missing a check variable I think
Also its missing the 2sided mtl option.

Important is the ability to change the hue values in the script and creating only 1 CC and/or modify excisting ones.

Anyone who can help me in the right direction?

--- get materials from selection
(
mymaterials = #()
for obj in selection do
(
    if obj.material != undefined do appendifunique mymaterials obj.material
)
 
--- check for multisubmtls and collect the submtls
mysubmaterials = #()
for a=1 to mymaterials.count do
(
    if classof mymaterials[a] == Multimaterial then -- if multisubmtl, then
    (
        for b=1 to mymaterials[a].materialList.count do --- loop through submtls
        (
            if mymaterials[a].materialList[b] != undefined then appendifunique mysubmaterials mymaterials[a].materialList[b] -- collect submtls
        )
    )
)
 
-- delete multisubs from matarray
for a=mymaterials.count to 1 by -1 do
(
    if classof mymaterials[a] == Multimaterial then deleteitem mymaterials a
)
 
-- append the submtls
for a=1 to mysubmaterials.count do
(
    appendifunique mymaterials mysubmaterials[a]
)
 
print mymaterials
 
-- see whats in the diffuse slot
for mymaterial in mymaterials do
(
    -- make sure its a standard material
    if classof mymaterial == VRayMtl then
    (
        --- make sure the diffuse slot is not empty
        if mymaterial.texmap_diffuse != undefined then
 
        (
            -- remember the map in the diffuse slot
            mymap = mymaterial.diffuseMap
 
            -- create a new cc node and wire it
            ccnode = ColorCorrection()
            ccnode.Map = mymap
 
            -- set cc settings
            ccnode.hueShift = -18.0
            ccnode.saturation = 0.0
            ccnode.tint = (color 0 0 0)
            ccnode.tintStrength = 0.0
			ccnode.gammaRGB = 0.75
            /*
            ccnode.rewireMode (Rewire_Mode) : integer
            ccnode.rewireR : integer
            ccnode.rewireG : integer
            ccnode.rewireB : integer
            ccnode.rewireA : integer
            ccnode.hueShift : float
            ccnode.saturation : float
            ccnode.tint (Hue_Tint) : fRGBA color
            ccnode.tintStrength (Hue_Strength) : float
            ccnode.lightnessMode : integer
            ccnode.contrast : float
            ccnode.brightness : float
            ccnode.exposureMode (Lightness) : integer
            ccnode.enableR : boolean
            ccnode.enableG : boolean
            ccnode.enableB : boolean
            ccnode.gainRGB (LightnessGainRGB) : float
            ccnode.gainR (LightnessGainR) : float
            ccnode.gainG (LightnessGainG) : float
            ccnode.gainB (LightnessGainB) : float
            ccnode.gammaRGB (LightnessGammaRGB) : float
            ccnode.gammaR (LightnessGammaR) : float
            ccnode.gammaG (LightnessGammaG) : float
            ccnode.gammaB (LightnessGammaB) : float
            ccnode.pivotRGB (LightnessPivotRGB) : float
            ccnode.pivotR (LightnessPivotR) : float
            ccnode.pivotG (LightnessPivotG) : float
            ccnode.pivotB (LightnessPivotB) : float
            ccnode.liftRGB (LightnessLiftRGB) : float
            ccnode.liftR (LightnessLiftR) : float
            ccnode.liftG (LightnessLiftG) : float
            ccnode.liftB (LightnessLiftB) : float
            ccnode.printerLights (LightnessPrinter) : float
 
		*/            
 
		-- put the cc node to the diffuse slot
            mymaterial.texmap_diffuse = ccnode  
 
 
        )
        else print "nothing in diffuse slot"
    )
)
)

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
sable806's picture

Working Code

The chunck of code i gave you was only the end of it i didn't took what you had already write above, so you needed to integrate what i coded in your base.

While looking at what you wrote, i think you have misunderstood where operations were going, you were adding a ccnode when there was already one, and you had twice the same test. Also the structure of and if else is the following :

if this = blabla then -- Firt test --
(
 
)
else if this = that then -- Second test if first hasn't succeed --
(
 
)
else -- Operations that will happen no matter what if test 1 and test 2 failed --
(
 
)

Here is the entire code which is working perfectly i've just tested it on my scene.

--- get materials from selection
(
mymaterials = #()
for obj in selection do
(
    if obj.material != undefined do appendifunique mymaterials obj.material
)
 
--- check for multisubmtls and collect the submtls
mysubmaterials = #()
for a=1 to mymaterials.count do
(
    if classof mymaterials[a] == Multimaterial then -- if multisubmtl, then
    (
        for b=1 to mymaterials[a].materialList.count do --- loop through submtls
        (
            if mymaterials[a].materialList[b] != undefined then appendifunique mysubmaterials mymaterials[a].materialList[b] -- collect submtls
        )
    )
)
 
-- delete multisubs from matarray
for a=mymaterials.count to 1 by -1 do
(
    if classof mymaterials[a] == Multimaterial then deleteitem mymaterials a
)
 
-- append the submtls
for a=1 to mysubmaterials.count do
(
    appendifunique mymaterials mysubmaterials[a]
)
 
print mymaterials
 
-- see whats in the diffuse slot
for mymaterial in mymaterials do
(
    if classof mymaterial == VRayMtl then
    (
        if (classOf mymaterial.texmap_diffuse) == Color_Correction then
        (
 
			ccnode = mymaterial.texmap_diffuse
			ccnode.saturation = 15.0
            ccnode.tint = (color 0 0 0)
            ccnode.tintStrength = 0.0m
			ccnode.gammaRGB = 0.75
 
        )
		else if (mymaterial.texmap_diffuse) == undefined then
		(
		)
		else
		(
			-- remember the map in the diffuse slot
            mymap = mymaterial.diffuseMap
 
            -- create a new cc node and wire it
            ccnode = ColorCorrection()
            ccnode.Map = mymap
 
            -- set cc settings
            ccnode.saturation = 15.0
            ccnode.tint = (color 0 0 0)
            ccnode.tintStrength = 0.0m
			ccnode.gammaRGB = 0.75
 
			-- put the cc node to the diffuse slot
            mymaterial.texmap_diffuse = ccnode
		)
	)
)
)

Tell me if it suits your needs.

I attach the .ms with it.

AttachmentSize
ccnode_fn.ms 1.86 KB
tarsonis's picture

Amazing! I owe you a beer!

Amazing! I owe you a beer! Big thanks! I had it nearly written down like this but I was missing this line:
ccnode = mymaterial.texmap_diffuse

Still a lot learning ahead. In my head it always works great ^^

If I now want to include 2Sided material. I thought I can put a further "else" operation like this but it seems its not allowed or I wrote it wrong?

...working script code above
 
else if (classof mymaterial) == VRay2SidedMtl then
(
	ccnode = m.frontmtl.texmap_diffuse
	ccnode = m.backmtl.texmap_diffuse
	ccnode.saturation = -15.0
        ccnode.tint = (color 0 0 0)
        ccnode.tintStrength = 0.0m
	ccnode.gammaRGB = 0.75
 
)
sable806's picture

2Sided

Sorry for the delay but i've been blocked by scriptspot anti spam system... Took so much time to get back here ..

This should work for 2sided materials

AttachmentSize
ccnode_fn.ms 3.85 KB
sable806's picture

Informations

I forgot to tell the following things, the script add color correction if it found a map in the diffuse slot, so it will apply whren there is a Noise or Cellular or Checker, or whatever maps max can have. If you want to restrict the CC node adding behavior to bitmaptexture, you just need to rewrite the if then loop with the right conditions. If that's what you need and yo ucannot get it working feel free to tell me.

sable806's picture

Color Correction test

What you want to do is when you test your diffuse Slot you want to have 3 cases : Case 1 you have nothing, nothing happen (if that's what you want to do) Case 2 you have a bitmap and the nyou want to plug this bitmap in a CC node and this CC ndoe into the diffuse slot (that's what you manage to do so far) Case 3 your diffuse slot has already a CC node, in this case you want to change the values.

In terms of code what it should look like.

for mymaterial in mymaterials do
(
  -- make sure its a standard material
  if classof mymaterial == VRayMtl then
  (
     if (classOf mymaterial.texmap_diffuse) == Color_Correction then
     (
        -- Set cc settings --
        ccnode.hueShift = -18.0
        ccnode.saturation = 0.0
        ccnode.tint = (color 0 0 0)
        ccnode.tintStrength = 0.0
	ccnode.gammaRGB = 0.75
     )
     else if mymaterial.texmap_diffuse) == undefined then
     (
        -- Do nothing --
     )
     else
     (
        -- Keep the code you had if it works the way you wanted --
     )
   )
)

Feel free to tell me if it's working !

tarsonis's picture

there are some bugs in that code

Thanks mate. The code is not working. One have to tell max what "ccnode.hueshift" actually is. This is missing in you script also some typing issue I think.

I got this now. But this in not working. I don't know what I'm missing. It seems so simple...

there are 3 condition
1. diffusemap = bitmaptexture (add CCnode + apply values)
2. diffusemap = CCnode + bitmaptexture (just change values)
3. diffusemap = just color (do nothing)

it gets even more complicated with 2Sided mat. for front and back mat set a CCnode

--- get materials from selection
(
mymaterials = #()
for obj in selection do
(
    if obj.material != undefined do appendifunique mymaterials obj.material
)
 
--- check for multisubmtls and collect the submtls
mysubmaterials = #()
for a=1 to mymaterials.count do
(
    if classof mymaterials[a] == Multimaterial then -- if multisubmtl, then
    (
        for b=1 to mymaterials[a].materialList.count do --- loop through submtls
        (
            if mymaterials[a].materialList[b] != undefined then appendifunique mysubmaterials mymaterials[a].materialList[b] -- collect submtls
        )
    )
)
 
-- delete multisubs from matarray
for a=mymaterials.count to 1 by -1 do
(
    if classof mymaterials[a] == Multimaterial then deleteitem mymaterials a
)
 
-- append the submtls
for a=1 to mysubmaterials.count do
(
    appendifunique mymaterials mysubmaterials[a]
)
 
print mymaterials
 
-- see whats in the diffuse slot
for mymaterial in mymaterials do
(
    -- make sure its a standard material
    if classof mymaterial == VRayMtl then
    (
        --- make sure the diffuse slot is not empty
        if (classOf mymaterial.texmap_diffuse) == Color_Correction then
 
        (
            -- remember the map in the diffuse slot
            mymap = mymaterial.diffuseMap
 
            -- create a new cc node and wire it
            ccnode = ColorCorrection()
            ccnode.Map = mymap
 
            -- set cc settings
            ccnode.saturation = 15.0
            ccnode.tint = (color 0 0 0)
            ccnode.tintStrength = 0.0m
			ccnode.gammaRGB = 0.75
            /*
            ccnode.rewireMode (Rewire_Mode) : integer
            ccnode.rewireR : integer
            ccnode.rewireG : integer
            ccnode.rewireB : integer
            ccnode.rewireA : integer
            ccnode.hueShift : float
            ccnode.saturation : float
            ccnode.tint (Hue_Tint) : fRGBA color
            ccnode.tintStrength (Hue_Strength) : float
            ccnode.lightnessMode : integer
            ccnode.contrast : float
            ccnode.brightness : float
            ccnode.exposureMode (Lightness) : integer
            ccnode.enableR : boolean
            ccnode.enableG : boolean
            ccnode.enableB : boolean
            ccnode.gainRGB (LightnessGainRGB) : float
            ccnode.gainR (LightnessGainR) : float
            ccnode.gainG (LightnessGainG) : float
            ccnode.gainB (LightnessGainB) : float
            ccnode.gammaRGB (LightnessGammaRGB) : float
            ccnode.gammaR (LightnessGammaR) : float
            ccnode.gammaG (LightnessGammaG) : float
            ccnode.gammaB (LightnessGammaB) : float
            ccnode.pivotRGB (LightnessPivotRGB) : float
            ccnode.pivotR (LightnessPivotR) : float
            ccnode.pivotG (LightnessPivotG) : float
            ccnode.pivotB (LightnessPivotB) : float
            ccnode.liftRGB (LightnessLiftRGB) : float
            ccnode.liftR (LightnessLiftR) : float
            ccnode.liftG (LightnessLiftG) : float
            ccnode.liftB (LightnessLiftB) : float
            ccnode.printerLights (LightnessPrinter) : float
 
		*/            
 
		-- put the cc node to the diffuse slot
            mymaterial.texmap_diffuse = ccnode 
 
        )
		else if (mymaterial.texmap_diffuse) == undefined then
		()
 
		else (mymaterial.texmap_diffuse) == ColorCorrection then
		(
			ccnode = ColorCorrection()
			ccnode.saturation = 15.0
            ccnode.tint = (color 0 0 0)
            ccnode.tintStrength = 0.0m
			ccnode.gammaRGB = 0.75
		)
	)
)
)

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.