Excitement of recreating the wheel

Hello techeez,

I am going to make a script to render out wireframe of selected object or objects.

I know their are plenty of scripts to do this, but I am going to make a new one just as a part of my learning, join me to share the idea,

I have started with creating the material and the shading group

import maya.cmds as mc
material = mc.shadingNode('lambert', asShader=1, name='WireframeMTRL')
SG = mc.sets(renderable=1, noSurfaceShader=1, empty=1, name='WireframeSG')
mc.connectAttr((material+'.outColor'),(SG+'.surfaceShader'),f=1)
item=str(mc.ls(sl=True)[0])
mc.sets(item, e=1, forceElement=SG)

well just here, when I have selected a object I am trying to assign it to it. but I get warning message, in script editor, although SG & matrial is created and connected
[I]

Warning: Cannot add the following items to the set since the set has restrictions on membership: WireframeMTRL1

Warning: None of the items can be added to the set # [/I]

I am doing the last step since objects and faces are never actually connected or assigned directly to materials. Each material is connected to a shadingEngine and this is connected to the objects to be shaded and put it to the shadingEngine set.

You’ve already connected the shader to the SG in line 4. Lines 5 and 6 are trying to add it to the SG as if it were a rendereable object – the ls call is getting the material, which is selected automatically after creation. You need to cache the selection up at the top of the script – move line 5 above the current line 2.

import maya.cmds as mc
item=str(mc.ls(sl=True)[0])
material = mc.shadingNode('lambert', asShader=1, name='WireframeMTRL')
SG = mc.sets(renderable=1, noSurfaceShader=1, empty=1, name='WireframeSG')
mc.connectAttr((material+'.outColor'),(SG+'.surfaceShader'),f=1)
mc.sets(item, e=1, forceElement=SG)
mc.setAttr(SG + ".miContourEnable", 1)
mc.setAttr(SG + ".miContourWidth", 0.80)
mc.setAttr("miDefaultFramebuffer.contourEnable", 1)
mc.setAttr("miDefaultFramebuffer.contourSamples", 2)

so finally I can have a wireframe shader created and applied to selected object like this, but if in global render settings Mental Ray is not selected, the last two lines of code above gives error saying miDefaultFramebuffer not found…

how do i change the global render settings to mental ray pythoniclly…? and what if whole mental ray plugin is not loaded should I prompt user to enable or do it in coding…

Enabling MR via script has always been a headache - there’s a lot of lame stuff in mental ray that does not work properly until a human has opened the UI, and finding out which things work like that is a long trial and error process (at least it is for me - if anybody else knows a bulletproof way to do it, please share!)

I’d cop out and just prompt the user to enable mental ray by hand.

well this code helps to load mental ray plugin


cmds.waitCursor( state=True )
ignoreUpdateCallback=True
try:
    cmds.loadPlugin('E:/Program Files/Autodesk/Maya2010/mentalray/plug-ins/Mayatomr.mll')
except:
    print(sys.exc_info()[0])
mel.eval('updatePluginUI( "56" );')
ignoreUpdateCallback =False
cmds.waitCursor( state=False )

however I hope some one can tell me to select the mental from the dropdown pythonically… or somehow query if mental ray as defualt renderer is selected or not ?

if not cmds.pluginInfo( "Mayatomr", query = True, loaded = True ):
    cmds.loadPlugin( "Mayatomr" )

cmds.setAttr(
    "defaultRenderGlobals.currentRenderer",
    "mentalRay",
    type = "string"
    ) 
	
if not cmds.objExists( "miDefaultOptions" ):
    mel.eval( "miCreateDefaultNodes" )

HTH.

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

alright got it supposed to create default nodes

Ok its done, I will show you the wheel once I have and extra GUI that shows up on pressing CTRL to choose the wire color or change the object color, and just one last question

if mental ray is not loaded i load it with the above method but since it takes time to set the default renderer by cmds.setAttr(‘defaultRenderGlobals.ren’, ‘mentalRay’, type=‘string’)

You can try


import time
time.sleep(1)

To pause for a second – but that is exactly the kind of crap that always happens to me when I try to run mental ray without going through the UI. You probably need to troll through all the MI scripts and find the one which actually creates miDefaultFramebuffer and make sure that it’s not in someplace dumb like a UI window definition file. Then make sure that contourEnable is always there and does not get added by some other UI action.

Of course, I am a vicious anti-mental ray bigot, so take this with a grain of salt.

well I made the script with ability to Load mental ray by itself to overcome this crap so I mentioned it in the read me to load MR and set it as default renderer as MR, I was playing with time.sleep so I enclosed the code inside waitCursor on and off(so that user thing something is in progress…) but I got waitCursor stack empty error…

I would just call miCreateDefaultNodes from a custom callback function and hook it using addCallback parameter in the loadPlugin command.

learning & playing simultaneously: the wheel re-invented