Turning On Caustics In A Script

I'm creating a utility script that, among other things, turns on caustics for you.

I tried using the command that comes up in the script editor and by itself it works fine:

setAttr "miDefaultOptions.caustics" 1;

Problem is, when I try to use this within a full script, I get the error:

// Error: line 21: No object matches name: miDefaultOptions.caustics //

Now, this is after confirming that Mental Ray is loaded and selected as the current render type.

My only guess as to why it works solo, but not within a script is that it is doing something that makes it not realize that miDefaultOptions is available, so it spits out an error.

So, what is the deep down, under the hood command to turn on caustics so that no matter what Maya is up to when I tell it to do this, it will understand what I'm talking about?

Alternately, I could try to change to the preset "Preview Caustics" if that were easier in MEL.

Thanks

Actulay its more likely caused by the fact that the mr plugin is not yet loaded. Try forcing the plug to load before you issue a setAttr.

Nope. Plugin is loaded.
It's set to autoload and there's even a call prior to trying to do this that sets mental ray as the renderer.

I know all that is working, because even when the script errors out, if you check the render settings, it is set to Mental Ray.

I'm not sure if this is related to your problem but I think it could be, from the docs:

:nathaN

QUOTE
loadPlugin command restriction
Do not include the loadPlugin command in the same script that uses the contents of a user-defined command plug-in. This is because the MELTM parser parses the entire script before executing any of it. When the script is parsed, the loadPlugin command will not yet have registered the command, therefore MEL will not be able to parse it.

Workaround
Use one script to load the plug-in and another to use the command it registers. Alternatively, you can use MEL's eval statement to wrap the call to the new command. This will delay MEL's parsing of the command until runtime and allow the script to be parsed correctly.