Notifications
Clear all

[Closed] Accessing Render Classes

I am trying to write a script that will auto setup Mental Ray or the Scan Line renderer with the best setting to render out an AO map in one click. I have found a script that gives me a good jumping off point but I have hit a stumbling block that I am not sure how to get around. My problem is that when trying to set values to the Mental Ray engine via script. I get an error saying the following…

–Unknown property: “Glossreflectionsprecision” in mental_ray_renderer

Now I understand what the error message is saying, the script can not find glossyreflectionsprecision, but I am not sure what I am doing wrong to cause the error to happen. Here is the code that I am working with.


on butMR pressed do 
( 
  varMR = "*mental_ray*" 
  checkRender varMR 
  mental_ray_renderer.glossyreflectionsprecision Float default:5.0 -- float 
)

I was reading the MAXScript help about the Mental Ray renderer and I think that the error is happening because I have not assigned mental_ray_renderer to the actual render that was chosen when the button was selected, but I am not sure how to go about doing that. Any help or a point in the right direction would be greatly appreciated.

16 Replies
2 Replies
(@dangrover)
Joined: 11 months ago

Posts: 0

I believe your diagnosis is correct!

variable = renderers.current

That’s the thing you’re after, I believe. So in your case, it’d be…

mental_ray_renderer = renderers.current

Edit: note, it might be best to do a test on this variable first – to check to see if it’s MR, Scanline, IRay etc.

(@billyclint)
Joined: 10 months ago

Posts: 0

Okay that got me a little further but now I have a new error.

– Type error: Call needs function or class, got :1.0

But I think that is because I did not place the variable you suggested in the correct location. I put it in the onn butMR pressed function as follows.


on butMR pressed do 
( 
 mental_ray_renderer = renderers.current 
 varMR = "*mental_ray*" checkRender 
 varMR mental_ray_renderer.glossyreflectionsprecision Float default:5.0 -- float 
)

I am thinking now that I should make this a global variable at the top of the file but after messing around with it I still do not have it working. Here is all of the code that I have. So far. Again not my code, just something I found to use as a starting off point.


-- script for quickly change render settings 
-- create by Bondar Igor :) 
var mental_ray_renderer = renderers.current 
if (( mainRoll != undefined) and ( mainRoll.isdisplayed)) do 
(destroyDialog mainRoll ) -- test if dialog exist fn 

checkRender nSearch = -- function check if render installed 

( theRenderer = for obj in RendererClass.classes where (matchPattern (obj as string) pattern:nSearch) -- check if the name in nSearch variable exist collect 
obj if theRenderer.count ==1 then renderers.current = theRenderer[1]() else ( messageBox "render not installed") ) rollout mainRoll "ChangeSetting" ( group "Change Render" -- define change render buttons ( button butScanline "Scanline" align:#left across:2 width:70 height:20 button butMR "Mental Ray" align:#left width:70 height:20 button butVray "Vray" align:#left across:2 width:70 height:20 button butKrakatoa "Krakatoa" align:#right width:70 height:20 ) 

on butScanline pressed do ( varScan = "*Scanline*" checkRender varScan ) 

on butMR pressed do ( varMR = "*mental_ray*" checkRender varMR --This is just a test to see if I can correctly grab a value and edit it. 
mental_ray_renderer.glossyreflectionsprecision Float default:5.0 -- float ) 

on butVray pressed do ( varVray = "V_Ray_Adv*" checkRender varVray ) 

on butKrakatoa pressed do ( varKrakat = "*Krakatoa*" checkRender varKrakat ) ) createDialog mainRoll 175 450

Sorry about the formatting it seamed to kill it when I put the code tags around it. I tried to clean it up the best that I could.

Okay I have made a little bit of progress so far. Well not that much as I have stopped the errors but I am not sure if the values that I am applying are sticking.

At the very top of my script I added the following variable and set it equal to the current render.

test = renderers.current()

Next down on my button I ma trying to change values like so.

test.glossyreflectionsprecision = .95 -- float

While the above code produces no error when run, I have a feeling that it is not working as I can not see anything update in the render settings window. Also I have been trying to log what I see by using the following code.

print(glossyreflectionsprecision)

Is there a better way to do this in max or will this way work. The reason I ask is because on of my print statements returns undefined and I just want to make sure that I am using that correctly to debug.

There are some… intracacies when it comes to editing the render dialog whilst it is open. Try running it with the render dialog closed, see if that works.

Also, after doing test = renderers.current(), try running a …

show test

It’ll show you all the available properties to edit.

So I have gotten a little bit further with my script now. I have now figured out how and why the values were not working but I am not sure why it was not working and that is the part that I would like to understand.

So after looking around in the 3Ds Max documentation I found out about the following line of code.

renderers.production = Default_Scanline_Renderer()

After testing with the above code everything started working but I am not sure why this is. Is,

renderers.production

a special set of keywords that you have to use when you want to do something with the render?

I was thinking that by doing the follwoing…

sLine = Default_Scanline_Renderer()

I could do the same things as doing…

renderers.production= Default_Scanline_Renderer()

I have tried other combinations of words and they do not work which makes me questions some things I thought I understood about programming.

For example I was under the impression that since I did something like the following.

sLine = Default_Scanline_Renderer()

I could use the something like this and it should work.

sLine.glossyreflectionsprecision = .95

However that does not work, well it does work but again I do not think that the values are being adjusted. So why does

sline.something

not work but

renderers.production.something

work?

Default_Scanline_Renderer() creates and returns a new instance of scanline renderer. You can change its parameters but it’s different from changing the parameters of current/production renderer. Only after you assign this renderer instance to renderers.production it will be interchangeable.

It’s the same as with materials, for example:

myMat = standardMaterial() -- creating material instance
myMat.diffuse = red -- changing some parameters
$myObject.material = myMat -- assigning it to an object, changes you've made will be now visible

Because when you use the constructor (ie Default_Scanline_Render()) you’re doing just that – “constructing” a new instance of the default scanline renderer. It’s easy to get confused because having multiple instances of the renderer makes little sense, but it’s directly comparable to, say, a material.

If you are editing an object’s material which happens to be a standard material, you’d be editing a standard material (maybe it’s called “Ziggy”). You can also create a new standard material (lets call it “Bowie”, a standard material), using the constructor “standardmaterial()”. Now, you can edit Bowie all you want, but it won’t change Ziggy at all. What you can do is APPLY Bowie to whatever object currently has Ziggy applied to it. But until you do that, you’re just editing a material that’s not applied to anything.

The same is true of renderers. So when you edit the parameters of a constructed instance of the default renderer, it doesn’t do anything until you apply it, When you edit renderers.current or renderers.production (which are basically the same thing, unless you’re in iterative or activeshade mode), you’re actually editing the currently applied renderer (so more akin to editing $.material, rather than creating a new material and then assigning it to $).

Hope that’s clear?

Edit: Haha. The same reply and even the same example as Vojtech.

Yeah that is making a bit of sense now. I am slowing getting this so thanks for the help so far. Now this brings me up to my next hurdle and that is accessing the Advanced Lighting render tab and setting the Advanced Lighting from nothing to Light Tracer.

I have been reading the documentation about them and I am not quite sure how to access them. I know that I have to something using the keyword Light_Tracer but I am not sure what. I am going to mess around in a side script and see if I can get it working. If you have any advice on where to look or what to do please let me know. I will post back if I get it working. Thanks for all the help so far.

What you are probably looking for is basically

SceneRadiosity.radiosity = Light_Tracer()

Maxscript reference is helpful in finding this sort of information, serach for light tracer, pick the first hit and look in the header. Just above Light_Tracer : RadiosityEffect you will find MAXScript Language Reference > 3ds Max Objects > RadiosityEffect : MAXWrapper > breadcrumbs, and clicking on RadiosityEffect : MAXWrapper will give you some overview on how to ‘Get/Set the radiosity plug-in’.

2 Replies
(@billyclint)
Joined: 10 months ago

Posts: 0

That worked out just great, thanks. I have been using the Maxscript help but I am afraid that sometimes I do not understand how to use the information that I am looking at. Or as in this case, I have no idea what I should be looking for but a rough idea on how to put it together. Now that I look a little bit more over the help file I see how I could have come up with this now.

It’s exactly the same as what I did before, first we set…

SceneRadiosity.radiosity = Light_Tracer()

Then we can do things like…

SceneRadiosity.radiosity.initial_sample_spacing = 0

I am still going to work on it and I will post back my results as I make them. I do really appreciate the help, I really feel like I am making some progress when it come to understanding more and about Maxscript.

(@davewortley)
Joined: 11 months ago

Posts: 0

I have a quick question about error checking and rather then start a new thread I thought I would just update this one. So I tried to add some error checking into the script and for some reason its not working. Here is the code that I have so far.


Rollout mainRoll "Unreal Multi Tool" ( group "Collision" ( button butCollision "Test"align:#left width:70 height:20 )

on butCollision pressed do 
( if $ != undefined then ( messagebox "Please select something to make collision." ) 
else if $ == geometry then
 ( The run the rest of the code)

I have been trying various things but I am not sure what to do or what to check against or if my logic for this is even correct. I am sure what I am over looking is crazy easy but it has me stumped for now. I can also post the rest of the code if needed. I just did not want to post a bunch of code if it was not needed.

I figured it out. All I needed to do was add the following line of code to my…


nodes = for node in selection where iskindof node GeometryClass collect node 
if nodes.count == 0 then (messageBox "You need to select an object")

But with the above code can you do something like node.type? I am really confused on what types of objects you can do the Dot operator on.

2 Replies
(@dangrover)
Joined: 11 months ago

Posts: 0

Try “classof”. It comes in the form of…

if classof $Direct01 == TargetDirectionallight do blahblahblah

If you want it to be just any sort of light, it’d be…

if superclassof $Direct01 == light do blahblahblah
(@billyclint)
Joined: 10 months ago

Posts: 0

I will give that a try as I think it has something do with the error that I am getting now. I am not sure if I should start a new thread or continue in this one as the tool has evolved now to include more than just changing the rendering engine. In the past few days I have added all of tools to it that I use on daily basis. I am now working on a slimmed down version of the RTT and have run into a weird issue that I think is related to the code above but I am not sure.

Page 1 / 2