Notifications
Clear all

[Closed] Help a Newbie write a simple script

Hi,

As I say I am new to scripting in any language, but MaxScript will gave to be the most important to me.
I’ve read lots on various pages on the Max help, but i’m struggling to have it click with me.

I need to write a script that will do the following;

select a named material
change some texture maps (always the diffuse, possible others),
render one camera,
save,
render another camera,
save,
etc etc
then close

I know this will be so simple to many (or most) but with what I have read in max docs and forums and tutorials etc.

I cant seem to even select a material or render a view.

I need some simple basic commands for the above to get me on the right track and i’m sure I can develop it from there as I go. But as yet i’ve had no luck understanding the autodesk help as I say.
I get the feeling that a lot of this is so simple that everyone assumes everyone knows it

Sorry if this is too basic for people but I need to get started somewhere and have not much time to get something usable (no matter how messy or imperfect it may be).

Hope someone can help
Thanks in advance,

EDIT; I have been using listener as a start but the comands relating to material s , texture changing and rendering either don’t shoe up or are not the same as they would be in a script I guess. They look different to that of the help doc’s etc…

21 Replies

I would 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"

-- iterate the cameras on the scene, using 'where' to ignore camera targets from the list
for cam in cameras where superclassof cam == camera do (
	-- 'activate' the camera
	viewport.setCamera cam

	-- render the current view and save it with a unique name
	render 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

Thank you SOO much for that, I can definitely get started with that!!!
I’m learning already.

I gave a quick test on the first 3 lines and got an error, think I’m doing something wrong.
See attached…

Thanks again!

I can’t see the error, did you attach an image? You can paste the console output here if uploading images doesn’t work.

(Sorry, I moved the link and it missed a ! off the front

OK, I see it now. It seems that the material is not found in the scene, do you have a material named “Material_1” assigned to any object?

I do yes, I only have one object and one material and I just re-assigned it and get the same error.

Also prior to posting on here I found this on my travels around the internet

for mat in scenematerials do
(
print (“material name: ” + mat.name)
)

Which returned the “Material_1”

Doh, sorry, the problem is that you used the wrong parameter on scenematerials, it should be

m = scenematerials[materialName]

Ah, of course!!

Sorry I miss read it obviously as a field I needed to fill in with my mat name.

I read somewhere that [] were for optional data so thought that I had to enter something.

(good example of why i’ve not got anywhere on my own I assume)

Works beautifully now, thank you, sorry if I wasted your time!

No doubt, i’ll do something else stupid and be back!

No problem

Page 1 / 3