This doesn’t seem to work. Has anyone had success with referenced scriptJobs? Within the source, all is well, when referenced it is dead. I tried making it self aware by adding in the namespace info, but it seems to not work anyway. I think I did it right, but it doesn’t compile right once referenced I guess. Here’s a test file i am trying to get to work when referenced.
AutomaticScriptCallOnAttributeChangeSampleFile.ma (109.1 KB)
Anyone have this issue and can share insight?
#Note: multi-line variable uses triple single quotes....
characterChangeCode = '''
import maya.cmds as cmds<a class="attachment"
def characterChanged() :
SelectedCharacter = cmds.ls(sl=True,long=True)
ControlParameter = "CharacterConfig"
obj_attr = (SelectedCharacter[0]+"."+ControlParameter)
print obj_attr
#get namespace to make sure it still works when referenced
namespace = SelectedCharacter[0].rpartition(':')[0]
#print ("The Namespace is "+namespace)
if cmds.getAttr(obj_attr)==0:
print "it's the yellow one"
cmds.setAttr((namespace+":CharacterMat.color"), 1, 1, 0, type='double3')
cmds.setAttr((namespace+":Hat.visibility"), 0)
cmds.setAttr((namespace+":Nose.visibility"), 0)
elif cmds.getAttr(obj_attr)==1:
cmds.setAttr((namespace+":CharacterMat.color"), 1, 0, 0, type='double3')
cmds.setAttr((namespace+":Hat.visibility"), 0)
cmds.setAttr((namespace+":Nose.visibility"), 1)
print "it's the red one"
elif cmds.getAttr(obj_attr)==2:
cmds.setAttr((namespace+":CharacterMat.color"), 0, 0, 1, type='double3')
cmds.setAttr((namespace+":Hat.visibility"), 1)
cmds.setAttr((namespace+":Nose.visibility"), 0)
print "it's the blue one"
elif cmds.getAttr(obj_attr)==3:
cmds.setAttr((namespace+":CharacterMat.color"), 0, 1, 0, type='double3')
cmds.setAttr((namespace+":Hat.visibility"), 1)
cmds.setAttr((namespace+":Nose.visibility"), 1)
print "it's the green one"
cmds.scriptJob(attributeChange=['CharacterCTRL.CharacterConfig',characterChanged])
'''
#get rid of it if it already exists and then remake it to prevent duplicates during editing
if cmds.objExists('scriptNodeCharacterChanged'):cmds.delete('scriptNodeCharacterChanged')
cmds.scriptNode( st=2, bs=characterChangeCode.replace("'''","''" ), n='scriptNodeCharacterChanged', stp='python')