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)