PDA

View Full Version : [Python] Basics and more


Darius1989
07-12-2012, 10:36 AM
Hello

Right a little about my background in coding... I did some scripts in maxscript back in the day. I looked over maya in recent months and now I decided to easy my live with a bit of python for maya...

I run in to few issues - which I will post here as I go but as start I have a little problem getting to work creating Layer Ovverides in render settings. Its something I'd like to set up for easy scene set up... Here is my python start and error I get... any hints where I went wrong ?

import maya.cmds as cmds
import maya.mel as mel

#Common
cmds.setAttr ('defaultRenderGlobals.enableDefaultLight', 0);

#Features
cmds.setAttr ('miDefaultOptions.scanline', 0);

#Quality

cmds.editRenderLayerAdjustment('miDefaultOptions.minSamples', 0);
cmds.setAttr('miDefaultOptions.minSamples', 2);
cmds.setAttr('miDefaultOptions.maxSamples', 2);
cmds.setAttr('miDefaultOptions.filter', 2);

I get this error

# Error: line 1: No object matches name: 0
# Traceback (most recent call last):
# File "<maya console>", line 12, in
# ValueError: No object matches name: 0 #
// Result: scriptEditorPanel1Window|TearOffPane|scriptEditorPanel1|formLayout37|formLayout39|paneLayout1|formLayout40|tabLayout2|formLayout65|cmdScrollFieldExecuter8 //
mentalRayOptionsCheckRenderer;miUpdateRenderQualityMenu scanline;
control -edit -enable true miMinSampleCtrl;
// Result: miMinSampleCtrl //


Now I was tring to change the 0 number at the end to 1/2 and erase it but I always get error :/

cmds.editRenderLayerAdjustment('miDefaultOptions.minSamples', 0);


Any hints where I went wrong? :s

Thanks, bye.

Darius1989
07-12-2012, 02:03 PM
Sorted I think I had miss spell or other issue... in any case...

cmds.editRenderLayerAdjustment ('miDefaultOptions.minSamples');

This creates layer override in render settings.

djx
07-12-2012, 02:38 PM
I'm guessing by your use of the semicolon at the end of each line that you are copying and pasting the mel output from the script editor and converting it to python. You almost got it right.

Problem 1: Maya delays the creation of some nodes until they are needed. In this case 'miDefaultOptions' may not exist until you open the render-settings window and select the quality tab. (Actually its a while since I dabbled in mentalray so someone may wish to correct me here). You can create it like this:

if not cmds.objExists("miDefaultOptions"):
mel.eval("miCreateDefaultNodes()")

Problem 2: The syntax is incorrect for the editRenderLayerAdjustment command. It should be:
cmds.editRenderLayerAdjustment('miDefaultOptions.minSamples')
Or if you want to, you can specify the layer you are adding the adjustment for
cmds.editRenderLayerAdjustment('miDefaultOptions.minSamples', layer='layer2')

I'd leave out the semi-colons too.

David

edit: Try and ignore the extra spaces that cgtalk loves to insert :shrug:

NaughtyNathan
07-12-2012, 03:55 PM
somebody should punch cgtalks code formatting square in the n uts

Darius1989
07-12-2012, 05:16 PM
Heya

Thanks very much ! I got it to work at the end :]

I'm now working on getting a nice UI - wish maya had max alike UI editor hehe :] I got a headache from trying to find how to move buttons + create sliders to add controls to my render set up haha fun !

Will be most likely back soon with more little tiny issues hehe :)

Thanks, bye.

Darius1989
07-17-2012, 09:22 PM
Heya

I got it roughtly where I wanted... the last think that wont let me sleep is to set up my AA filter to be custom... what is the darn command for it ?
I went over DefaultOptions and MentalRayOptions as well as render globals and I cant find it or im blind arr :/

CGTalk Moderation
07-17-2012, 09:22 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.