Notifications
Clear all

[Closed] Help a Newbie write a simple script

Sorry to emulate Columbo but “one more thing”…

Where do I put the camera names? in place of where you have written “cam”?
Also when you put viewport.setCamera I assume this would not work if max runs in silent mode with no UI? (Don’t think it matters at this point yet, maybe in the future)…

I assumed you wanted to use all the cameras on the scene, to specify the names of the cameras you want to use you can do something like this:

-- Specify the name of the material you want to change
materialName = "myMaterial"

-- Get the material by name
m = scenematerials[materialName]

-- Replace the diffuse map to a different texture, use 'show m' in case you want 
-- to know how are called the other channels (bump map, reflection, refraction, ...)
m.diffuseMap.fileName = @"path\to\the\texture.jpg"

-- Camera names to use
renderCameras = #("PhysCamera001", "PhysCamera002")

-- iterate the cameras names
for cameraName in renderCameras do (

	-- get the camera by name
	cam = getNodeByName cameraName

	-- render the camera and save it with a unique name
	render camera:cam outputfile:(maxfilepath + materialName + "_" + cam.name + "_render.png")

	-- save the scene 
	savemaxfile (maxfilepath + materialName + "_" + cam.name + "_scene.max")

)

-- In case you want to close max (?)
--quitMax #noPrompt

Notice I’ve also removed setCamera in case i would cause problem rendering in batch mode.

Ah, sorry, yeah there could be 10 or so cameras to cover all sides of the model, I was looking for a way to render one at a time.

Thanks, will give this a bash!!

You have to get used to reading maxscript error messages:

– Unable to convert: undefined to type: String

Means that is trying to combine a “thing that does not exist” with a string, maxscript doesn’t know how to do that and raises an error. If you read a bit further you’ll see that the culprit is the variable “texture”

– Locals:
– texture: undefined

It fails when it tries to combine maxfilepath + texture + “_” … to build the output file path because you haven’t defined the value of texture.

Fantastic, this is the kind of info I need to learn. It’s so hard to get this kind of “English” terminology etc when reading online documentation. Would take me years to learn with the amount of time I have to dedicate to it.
So just a few key lines of code and a few descriptions like you have done and it makes so much more sense to me.

I can build from this now with more confidence.

I just wanted to ask (as I got confused with online info) about the render settings.

As some commands render() for example. Use render dialogue settings and some ignore them.
I assume this method uses the settings already stored in the renderer?

Thanks again for your time, really appreciated.

No worries. Yep, render() by default uses most of the render settings of the current scene, but you can override them if you want to. For instance you can specify a different render resolution than the current one using:

render outputwidth:800 outputheight:600

Thanks, its working up to the save. (Testing with 2 cameras to satrt)

render camera:cam outputfile:(maxfilepath + “Texture” + “_” + “cam.name.png”)

I want to save to a subfolder of maxfilepath and tried “maxfilepath\Output” and it didn;t work.

And the second image overwrites the first…

You are building the output file path incorrectly. You should check how maxscript string operations work.

(maxfilepath + "Texture" + "_" + "cam.name.png")

this piece of code will join the value of maxfilepath, (the path of the current scene) with the string literals “Texture”, “_” and “cam.name.png”, you will end up with a file name that always is something like this: “C:\USER\Scenes\Texture_cam.name.png”. This happens because you are enclosing between quotes the variables you want to use.

You should use something like:

(maxfilepath + texture + "_" + cam.name + ".png")

to build a string with the actual values stored in texture and cam.name.

Ah that makes sense, although I still cant get it to add \output to the maxfilepath. tried a few different ways.
(Output) an existing subfolder to the one the max file is in)

Page 2 / 3