Announcement

Collapse
No announcement yet.

Maya python

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Maya python

    Heya

    Smashing my head here... How can I add a Reflection/refraction/etc layer using python command ?

    Thanks, ciao.
    CGI - Freelancer - Available for work

    www.dariuszmakowski.com - come and look

  • #2
    You mean a render element?

    Best regards,
    Vlado
    I only act like I know everything, Rogers.

    Comment


    • #3
      Code:
      import pymel.all as pm
      reflection = pm.mel.eval('vrayAddRenderElement("reflectChannel")')
      refraction = pm.mel.eval('vrayAddRenderElement("refractChannel")')
      Like this ?
      Or renderLayer ?
      www.deex.info

      Comment


      • #4
        I mean render element like LightSelect. Trying to write python based(not pymel...sry) to create LightSelect per light in scene for selected render layer...

        I think I can use

        import maya.cmds as cmds
        cmds.setAttr('vrayAddRenderElement('reflectChannel ')') if bigbossfr aproach will work... not sure I'm not at home :/

        thanks tho !
        CGI - Freelancer - Available for work

        www.dariuszmakowski.com - come and look

        Comment


        • #5
          Code:
          import maya.mel as mel
          reflection = mel.eval('vrayAddRenderElement("reflectChannel")')
          refraction = mel.eval('vrayAddRenderElement("refractChannel")')
          www.deex.info

          Comment


          • #6
            Howdy

            bigbossfr - your script work like charm ! But I'm still trying to get it to work in python.


            So far this command

            cmds.addAttr('vrayAddRenderElement("reflectChannel ")')

            give me

            # Error: No object matches name: vrayAddRenderElement("reflectChannel")
            # Traceback (most recent call last):
            # File "<maya console>", line 1, in <module>
            # ValueError: No object matches name: vrayAddRenderElement("reflectChannel") #

            this error:/


            Also side note how do I get somethink linked to lightselect node? I cant quite figure it out and youtube vray channel dont show it :s or Im blind/deaf
            CGI - Freelancer - Available for work

            www.dariuszmakowski.com - come and look

            Comment


            • #7
              The script that bigbossfr posted is in Python.

              The light select element is a set; you use the Relationship Editor in Maya to assign lights to it.

              Best regards,
              Vlado
              I only act like I know everything, Rogers.

              Comment


              • #8
                Do you know Python ?

                Because :
                Code:
                cmds.addAttr('vrayAddRenderElement("reflectChannel ")')
                will not work...

                addAttr is to add attributes on a node. Here, you not add an attribute, you want to create a renderElement.
                So, like i wrote, the command in Python is :

                Code:
                import maya.mel as mel
                reflection = mel.eval('vrayAddRenderElement("reflectChannel")')
                refraction = mel.eval('vrayAddRenderElement("refractChannel")')
                With the Maya mel module, because "vrayAddRenderElement" is a mel command.

                Or :
                Code:
                import pymel.all as pm
                reflection = pm.mel.eval('vrayAddRenderElement("reflectChannel")')
                refraction = pm.mel.eval('vrayAddRenderElement("refractChannel")')
                With the PyMel module.

                If i understand, you want to create lightSelect for each light in each renderLayer.

                For this in Python :
                You list all renderLayers :

                Code:
                import maya.cmds as cmds
                allRenderLayers = cmds.ls(type = "renderLayer")
                After, you list all lights :
                Code:
                allLights = cmds.ls(type = "renderLayer")
                Now for each layer, and each light, you create one renderElement light select, linked ton the light :
                Code:
                import maya.cmds as cmds
                import maya.mel as mel
                allRenderLayers = cmds.ls(type = "renderLayer")#get all renderLayers
                for myLayer in allRenderLayers:
                    cmds.editRenderLayerGlobals( currentRenderLayer=myLayer )#swtich to current renderLayer
                    lightType = cmds.listNodeTypes( 'light' )#get all lights type
                    for eachType in lightType:
                        for myLight in cmds.ls(type = eachType):#get all lights for each of type light
                            transform = cmds.listRelatives(myLight, p = True)#transform of the light
                            renderElement = mel.eval('vrayAddRenderElement("LightSelectElement")')#create the light select
                            cmds.sets(myLight, addElement = renderElement)#connect the light to the render element
                            cmds.rename(renderElement, "lightSelect_" + myLayer + "_" + transform[0])#rename your renderElement
                But, Maya python module is shit.
                Use Pymel :

                Code:
                import pymel.all as pm
                
                for myLayer in pm.RenderLayer.listAllRenderLayers():
                    myLayer.setCurrent()
                    for eachType in pm.listNodeTypes( 'light' ):
                        for myLight in pm.ls(type = eachType):
                            renderElement = pm.mel.eval('vrayAddRenderElement("LightSelectElement")')
                            set = pm.PyNode(renderElement)
                            set.add(myLight)
                            set.rename("lightSelect_" + myLayer.name() + "_" + myLight.firstParent())
                But, this 2 workflows are shit. You will have a scene with a lot of "light select". And if you add a lightz, it will be a nightmare to manage...

                Use the powerfull V-Ray Scene Access to create this on fly.

                On render global, in Vray common ---> post translate python script, add this :

                Code:
                import vray.utils as vr
                
                for myLight in vr.findByType("Light*") + vr.findByType("MayaLight*"):
                    name = "lightSelect_" + myLight.name()
                    vr.create("RenderChannelColor", name)
                    lightSelect = vr.findByName(name)
                    lightSelect[0].set("name", name)
                    myLight.set("channels", [lightSelect[0]])
                Now render and see what it's happened.
                With this, you add renderLayers, lights, what you want, vray will create all renderElements on the fly.
                Nothing to manage, nothing to update, nothing to do.
                Last edited by bigbossfr; 21-08-2012, 02:55 PM.
                www.deex.info

                Comment


                • #9
                  +1 on bigbossfr's post-translate method, I created a simple gui/light select manager which simply adds a custom user attribute to the lights you want light selects on, then the post translate script is almost identical to bigbossfr's except it checks for the custom attribute - easy!

                  Comment


                  • #10
                    Heya

                    Thanks a lot for help ! Ur script do make a lot of sens. I guess I was digging the wrong way around... As to me know python well... I'm learning it from few months so its WIP and a lot of mistakes hehe

                    Thanks, ciao.
                    CGI - Freelancer - Available for work

                    www.dariuszmakowski.com - come and look

                    Comment


                    • #11
                      Zoweee! I tip my hat to you bigbossfr. I feel like I just went to school after reading that post. Great info.
                      http://www.a52.com

                      Comment


                      • #12
                        btw, Vlado...any future in python module for vray? Has someone else done this? Just checking brefore I re-invent the wheel.

                        Thanks to all.

                        -ctj
                        http://www.a52.com

                        Comment


                        • #13
                          There is a plan to port the Python callback for V-Ray Standalone (almost done too), but for the moment, that's it. It only includes methods for manipulating the V-Ray scene before the rendering, same as in Maya. And it's already starting to be a headache, as linking against Python is causing all sorts of issues with applications that already have Python.

                          Other than that, can you explain a bit what do you expect to do with such a Python module?

                          Best regards,
                          Vlado
                          I only act like I know everything, Rogers.

                          Comment


                          • #14
                            Heya

                            Another bit of script im fighting with... Trying to write a simple ui to change subd/intensity etc on all selected lights. I got most of light setting covered but not the subd/intens... for some reason I cant get it to work

                            Have a look let me know where run wrong... for some reason lights in vray are very weird...


                            Code:
                            import maya.cmds as cmds
                            
                            def subD(*args):
                            	textFieldAinput = cmds.textField('subDiv',q=True,text=True)
                            	#print textFieldAinput
                            	lightlist = cmds.ls(sl=1)
                            	print lightlist
                            	for relatives in lightlist:
                            		
                            		litShape = cmds.listRelatives(relatives, c=True)
                            		#hierlist = cmds.select(lightlist, hi=1)
                            		for lights in litShape:
                            			#try:
                            			#test = cmds.setAttr('%s.%s'%(lights, 'intensityMult'), textFieldAinput)
                            	
                            			test = cmds.setAttr('%s.%s'%(lights, 'subdivs'),textFieldAinput)
                            	
                            	
                            			print test
                            			#except:
                            			#	pass
                            '''		
                            ba=cmds.ls(sl=1)
                            da=cmds.select(ba,hi=1)
                            print ba
                            for objects in ba:
                            	try:
                            		cmds.setAttr('%s.%s'%(objects,'intensityMult'), 5025)		
                            	except:
                            		pass
                            	
                            	'''		
                            if cmds.window(window, exists=True):
                            	cmds.deleteUI(window)
                            cmds.window(w=200,h=200)
                            cmds.showWindow()
                            cmds.columnLayout()
                            cmds.text(l='Subdivision')
                            cmds.textField('subDiv',cc=subD)
                            CGI - Freelancer - Available for work

                            www.dariuszmakowski.com - come and look

                            Comment

                            Working...
                            X