Help with maxscript

Hi !
Looooong time ago, a buddy gave me that script to render objects with several material and save the still automatically with a name convention. Ideal for this routine
I would like to use it again but it’ll be more efficient if Vray frame Buffer,Vray color mapping and max gamma preference could be take into account. I mean, I would like to be able to use fully this script with Vray.

My problem is … I’m not a maxscripter ! and I don’t know if there is a easy way to do it…

Could you help me ?

Thanks.

on vasy pressed do
(
    outputpath = GetSavePAth "Sauver dans : "
    for obji in objectTorender.selection do
    (
      -- print objectTorender.items[obji]
        obj = getnodebyname objectTorender.items[obji]    
        max unhide all
        select obj
        max hide inv
        for dec in $decor do
        (
        unhide dec
        )
        for mati in matTorender.selection do
        (
            obj.material = meditMaterials[mati]
            nomobj = obj.name
            matname = obj.material.name
            sortie = outputpath + "\\" + nomobj + "_" + matname + ".png"
            render  outputwidth:RenderWidth outputheight:RenderHeight outputFile:sortie vfb:myCheckBox.checked

        )
    )    

    messageBox "RENDER OK"
)

)

I’m not sure I understand what you’re trying to do.

Do you want to cycle through all your scene materials and render one image with all the objects with Material#1 then one image with all the objects with Material#2 then one image with all the objects with Material#3 etc.?

In fact, I’m already use this script in that way :

1-Create a “decor” group which been not affected by material changes and been always rendered.
2-Select objects and materials I want to associate in differents renders.
3-render them all !

So If I have a scene with box1/box2/box3 with material000 and material#1/material#2/material#…/material#25.

I can render :
- box1/box2 always with the same material000 and box3 with material#1 then save to “box3_mat#1.png” then,
- box1/box2 always with the same material000 and box3 with material#2 then save to “box3_mat#2.png” then,
- …
- box1/box2 always with the same material000 and box3 with material#25 then save to “box3_mat#25.png”.

So, this script is ok in that way but my problem is that It didn’t take in account all my stuff with VrayfB,Vray color mapping and max gamma preference, etc…
I don’t know why… that’s my request.
Sorry if I’m not clear… it’s no more in my mind !!

OK, try this:

on vasy pressed do
(
    outputpath = GetSavePath "Sauver dans : "
    for obji in objectTorender.selection do
    (
      -- print objectTorender.items[obji]
        obj = getnodebyname objectTorender.items[obji]    
        max unhide all
        select obj
        max hide inv
        for dec in $decor do
        (
        unhide dec
        )
        for mati in matTorender.selection do
        (
			obj.material = meditMaterials[mati]
			nomobj = obj.name
			matname = obj.material.name
			renderSceneDialog.close()
			rendOutputFilename = outputpath + "\\" + nomobj + "_" + matname + ".png"
			max quick render
        )
    )    
    messageBox "RENDER OK"
)
)

Obviously I can’t test it without the rest of your script.

Thanks Dan !
I’ve got a problem with this one… really strange, I don’t have any saved images
Here the (full )new one if you want to test :

rollout exportgm "Export GM"

(
label label0d "** \\GM_RENDERER// **"
MultiListBox objectTorender "Objects:" items:(for o in objects collect o.name)
MultiListBox matTorender "Materials:" items:(for o in meditMaterials collect o.name)

label label6d "======================="
Button vasy " RENDER THEM ALL!! "
label label7d "======================="

on vasy pressed do
(
    outputpath = GetSavePath "Sauver dans : "
    for obji in objectTorender.selection do
    (
      -- print objectTorender.items[obji]
        obj = getnodebyname objectTorender.items[obji]    
        max unhide all
        select obj
        max hide inv
        for dec in $decor do
        (
        unhide dec
        )
        for mati in matTorender.selection do
        (
            obj.material = meditMaterials[mati]
            nomobj = obj.name
            matname = obj.material.name
            renderSceneDialog.close()
            rendOutputFilename = outputpath + "\\" + nomobj + "_" + matname + ".png"
            max quick render
        )
    )    
    messageBox "RENDER OK"
)
)

createDialog exportGM width:200

I think it wasn’t saving because the ‘Save file’ checkbox wasn’t checked. I’ve added a line to do that automatically now and it’s saving files here.

try (destroyDialog exportgm);catch()
rollout exportgm "Export GM"

(
label label0d "** \\GM_RENDERER// **"
MultiListBox objectTorender "Objects:" items:(for o in objects collect o.name)
MultiListBox matTorender "Materials:" items:(for o in meditMaterials collect o.name)

label label6d "======================="
Button vasy " RENDER THEM ALL!! "
label label7d "======================="

on vasy pressed do
(
    outputpath = GetSavePath "Sauver dans : "
    for obji in objectTorender.selection do
    (
      -- print objectTorender.items[obji]
        obj = getnodebyname objectTorender.items[obji]    
        max unhide all
        select obj
        max hide inv
        for dec in $decor do
        (
        unhide dec
        )
        for mati in matTorender.selection do
        (
            obj.material = meditMaterials[mati]
            nomobj = obj.name
            matname = obj.material.name
            renderSceneDialog.close()
            rendOutputFilename = outputpath + "\\" + nomobj + "_" + matname + ".png"
			rendSaveFile = true
            max quick render
        )
    )    
    messageBox "RENDER OK"
)
)

createDialog exportGM width:200

Hi,
sorry for the delay, thanks Dan for the last version of the script, It works nicely !
I had a break with this job so I put it aside but it’s back again these days… and it came back with new demands…
Anyway, I handled almost all but again, I have a question about this script :

Could it be possible to get materials from a specific MatLib instead of taking them from Material Editor ? Idealy, if we could have the choice, it would be perfect !

I tried but I can’t understand how to call and get a specific matlib…

Could you help me please ?

Thanks

Glad the last one worked :slight_smile:

Have a try with this:

try (destroyDialog exportgm);catch()

rollout exportgm "Export GM"
(
	local matlib = meditMaterials

	label label0d "** \\GM_RENDERER// **"
	radioButtons matSource labels:#("Mat Editor","Mat Library") default:1 columns:2
	MultiListBox objectTorender "Objects:" items:(for o in objects collect o.name)
	MultiListBox matTorender "Materials:" items:(for o in matlib collect o.name)
    label label6d "======================="
	Button vasy " RENDER THEM ALL!! "
	label label7d "======================="

	on matSource changed state do
	(
		case state of
		(
			1:
			(
				matlib = meditMaterials
				matToRender.items = (for o in matlib collect o.name)
			)
			2:
			(
				matlib = undefined
				matToRender.items = #()
				if (matLibFP = getOpenFileName caption:"Select material library" filename:(getDir #matlib + @"\") types:"Material libraries(*.mat)") != undefined do
				(
					matLib = loadTempMaterialLibrary matLibFP
					matToRender.items = (for o in matlib collect o.name)
				)
			)
		)

	)

	on vasy pressed do
	(
		outputpath = GetSavePath "Sauver dans : "
		for obji in objectTorender.selection do
		(
		  -- print objectTorender.items[obji]
			obj = getnodebyname objectTorender.items[obji]    
			max unhide all
			select obj
			max hide inv
			for dec in $decor do
			(
			unhide dec
			)
			for mati in matTorender.selection do
			(
				obj.material = matlib[mati]
				nomobj = obj.name
				matname = obj.material.name
				renderSceneDialog.close()
				rendOutputFilename = outputpath + "\\" + nomobj + "_" + matname + ".png"
				rendSaveFile = true
				max quick render
			)
		)    
		messageBox "RENDER OK"
	)
)

createDialog exportGM width:200

I have to admit, I haven’t tested it properly but it should work…

Hi Dan,
You are the man !!!
Thanks a lot, it works perfectly !

Thanks for all your help

No problem, it’s good exercise for my brain :slight_smile: