Announcement

Collapse
No announcement yet.

Help with making Automated VRayToon assignment script better

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

  • Help with making Automated VRayToon assignment script better

    Hi there,

    MEL is not my forte, however I wrote this very simple script, basically select objects and then run it and it'll automatically assign a VRayToon shader to all selected objects.

    Code:
    global proc vrayPen(){
    
    // 	
    
    int $i;
    
    string $vtoonset = ("set_vrayToonPen" + $i);
    string $vtoon = ("toon_vrayToonPen" + $i);
    string $myNode = `createNode VRayToon -n $vtoon -ss`;
    
    sets -n $vtoonset;
    connectAttr -f ($vtoonset +".memberWireframeColor") ($vtoon + ".excludeList");
    setAttr ($myNode + ".excludeType") 1;
    
    print "// Result: Successfully assigned VRayToon to selected objects";
    
    }
    However, I do not know how ot create a + counter for the $vtoon and $vtoonset values so one could run the script multiple times. As it stand the script will work once due per scene due to it relying on incremental names. Can someone please help in adding this?
    Last edited by snivlem; 18-01-2012, 08:29 PM.
    Maya 2020/2022
    Win 10x64
    Vray 5

  • #2
    Just translated that to pymel and added some stuff. For now it just works for polymeshes and nurbs, dunno if others are needed. The numbering just starts with '01' and increments when additional nodes and sets are created by the script.

    Code:
    import pymel.core as pm
    
    def vrayPen():
        '''Adds the current selection to a set and connects that to a VRayToonNode'''
        selection = pm.ls(selection = True)
        objects = []
        
        for each in selection:
            shape = each.getShape()
            if shape.nodeType() == 'mesh' or shape.nodeType() == 'nurbsSurface':
                objects.append(each)
                
        if objects:
            toonSet = pm.sets(name = 'set_vrayToonPen01')
            toonNode = pm.createNode('VRayToon', name = 'toon_vrayToonPen01')
            toonSet.usedBy[0] >> toonNode.excludeList
            toonNode.excludeType.set(1)
            
            print ('Assigned ' +toonNode +' to obbjects: ')
            for each in objects:
                print each
            
        else:
            print 'Please select some objects first!'
            
            
    vrayPen()

    Comment


    • #3
      Ah, this is brilliant. Thank you.

      Should probably learn pymel or python instead of MEL maybe.
      Maya 2020/2022
      Win 10x64
      Vray 5

      Comment


      • #4
        Hi pechart,

        I was wondering on how to add "groups" to your script so it adds the toon shader to groups as well as mesh or nurbs surfaces.

        if shape.nodeType() == 'mesh' or shape.nodeType() == 'nurbsSurface':
        It should be (in my mind ) shape.nodeType() == 'transform', but obvioiusly that fails.
        Maya 2020/2022
        Win 10x64
        Vray 5

        Comment


        • #5
          You could just skip the if-statement and assign whatever you have selected:

          Code:
          import pymel.core as pm
          
          def vrayPen():
              '''Adds the current selection to a set and connects that to a VRayToonNode'''
              selection = pm.ls(selection = True)
              objects = []
              
              for each in selection:
                  #shape = each.getShape()
                  #if shape.nodeType() == 'mesh' or shape.nodeType() == 'nurbsSurface':
                  objects.append(each)
                      
              if objects:
                  toonSet = pm.sets(name = 'set_vrayToonPen01')
                  toonNode = pm.createNode('VRayToon', name = 'toon_vrayToonPen01')
                  toonSet.usedBy[0] >> toonNode.excludeList
                  toonNode.excludeType.set(1)
                  
                  print ('Assigned ' +toonNode +' to obbjects: ')
                  for each in objects:
                      print each
                  
              else:
                  print 'Please select some objects first!'
                  
                  
          vrayPen()

          Comment

          Working...
          X