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.

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? :slight_smile:

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.


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()

Ah, this is brilliant. Thank you.

Should probably learn pymel or python instead of MEL maybe. :slight_smile:

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 :slight_smile: ) shape.nodeType() == ‘transform’, but obvioiusly that fails.

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

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()