Feb 2013
1 / 3
Feb 2013
Mar 2013

What do I have to do to use  exclusiveLightCheckBox with custom light node?

When doing

exclusiveLightCheckBox -light $myLight;

I get error of "Invalid light."

  • created

    Feb '13
  • last reply

    Mar '13
  • 2

    replies

  • 1.5k

    views

  • 1

    user

28 days later

Are you using the transform node and not the light's shape node? This is fairly important for it to work. Just for fun I had a go at doing it in python though; the power of that mel command is the fact that the light may be moved and reparented in the DAG and it will still work so I used the API to mimic that behaviour:

from maya import cmds
from maya import OpenMaya
 
class ExclusiveLightCheckBox(object):
    def __init__(self, inLight, inLabel=None, inWidth=200):
        self.light = inLight
        if not inLabel:
            self.label = inLight.fullPathName().rsplit('|')[-1]
        self.width = inWidth
 
    def getCheckBox(self):
        print self.light.fullPathName()
        if self.light.isValid():
            cb = cmds.checkBox( label=self.label, width=self.width, ofc=self.exclude, onc=self.include )
            #set default state
            if 'defaultLightSet' in cmds.listConnections('%s.instObjGroups[0]'%self.light.fullPathName(), s=False):
                cmds.checkBox(cb, e=True, v=True)
            return cb
 
    def exclude(self, e):
        if self.light.isValid():
            cmds.disconnectAttr('%s.instObjGroups[0]'%self.light.fullPathName(), 'defaultLightSet.dagSetMembers', na=True)
 
    def include(self, e):
        if self.light.isValid():
            cmds.connectAttr('%s.instObjGroups[0]'%self.light.fullPathName(), 'defaultLightSet.dagSetMembers', na=True)
 
#create a light, get it's transform and then get the MDagPath
#so that light1.fullName keeps working when the light gets reparented
light = cmds.spotLight(coneAngle=45)
light = cmds.listRelatives( light, p=True, f=True )[0]
 
list = OpenMaya.MSelectionList()
OpenMaya.MGlobal.getSelectionListByName(light, list)
 
lightPath = OpenMaya.MDagPath()
list.getDagPath(0, lightPath)
 
#create a window with the custom checkbox
w = cmds.window()
cmds.columnLayout()
ExclusiveLightCheckBox(lightPath).getCheckBox()
cmds.showWindow(w)

Thankyou Trevor. I ended up using regular checkBox - it seems to work, although I didn't try reparenting my lights.
Thanks for your code, I'll take a look when I get some time.

Here's my code if someone needs it:

global proc mfdlSwitchDefaultIllumination(string $nodeWithAttr)
{
    string $connections[] = listConnections -p 1 (PlugToNode($nodeWithAttr) + ".instObjGroups[0]");
    for($c in $connections) {
        if(PlugToNode($c) == "defaultLightSet") {
            disconnectAttr (PlugToNode($nodeWithAttr) + ".instObjGroups[0]") $c;
            return;
        }
    }
    //no connection exists
    connectAttr -nextAvailable (PlugToNode($nodeWithAttr) + ".instObjGroups") defaultLightSet.dagSetMembers;
}

global proc AEmfIlluminatesByDefault_New(string $nodeWithAttr)
{
    {
        setUITemplate -pst attributeEditorTemplate;
        rowLayout;
            checkBox -label "Illuminates By Default" mfdlBreakDefaultLightLinkCheckBox;
        setParent ..;
        setUITemplate -ppt;
    }
    AEmfIlluminatesByDefault_Replace($nodeWithAttr);
}

global proc AEmfIlluminatesByDefault_Replace (string $nodeWithAttr)
{
    checkBox -e -cc ("mfdlSwitchDefaultIllumination " + $nodeWithAttr) mfdlBreakDefaultLightLinkCheckBox;
    //check if connection exists
    int $b_connectionExists = 0;
    string $connections[] = listConnections -p 1 (PlugToNode($nodeWithAttr) + ".instObjGroups[0]");
    for($c in $connections) {
        if(PlugToNode($c) == "defaultLightSet") {
            $b_connectionExists = 1;
            break;
        }
    }
    checkBox -e -v $b_connectionExists mfdlBreakDefaultLightLinkCheckBox;
}

Suggested Topics

Want to read more? Browse other topics in Maya or view latest topics.