Why scriptJob doesnt work in case of attrControlGrp

miContourEnable is enabled but still it doesnt gets updated on selection ch

def update():
    shapes = cmds.ls(sl = True, o = True, dag = True, s = True)
    if len(shapes) == 0:
		materials = "lambert1";
    else:
        shadingEngines = str(cmds.listConnections(shapes, type = "shadingEngine")[0])
        #connected materials
        materials = str(cmds.ls(cmds.listConnections(shadingEngines), materials = True)[0])
    print cmds.nodeType(materials)
    if cmds.nodeType(materials)=='surfaceShader':
        contourControl=cmds.attrControlGrp("contourControl",edit= True,attribute='contourSG.miContourWidth', l='Contour Width' )
        return contourControl
    else:
        contourControl=cmds.attrControlGrp("contourControl",edit= True,attribute=shadingEngines+'.miContourWidth', l='Contour Width' )
        return contourControl



cmds.window( title='Contour Widths' )
cmds.columnLayout()
cmds.attrControlGrp("contourControl",attribute='initialShadingGroup.miContourWidth', l='Contour Width' )
cmds.scriptJob(parent="wirewidthControl",e=["SelectionChanged","update()"])
cmds.showWindow()

scriptJob is referenceing ‘wirewidthControl’ which isn’t in your sample.

Unless it we’re missing some context, it looks like you’re trying to get a return value from your callback. Who’s supposed to be getting that? The callback is implicitly in the global scope (you’re calling via string name) so it’s got nobody waiting for the return value. You’d be better off with a class that had an update method so it could keep state in between firings of the callback.

thanks felt like a blind a nd dum b , think i should take a break …

so instead of wirewidthControl it should be contourControl with no return from update method…

forgive me my lord, i am naive and innocent…

no man, I made all the changes and i still dont see it chang in the slider, here i repost the code below…


def update():
    #selection goodness
    shapes = cmds.ls(sl = True, o = True, dag = True, s = True)
    if len(shapes) == 0:
		materials = "lambert1";
    else:
        shadingEngines = str(cmds.listConnections(shapes, type = "shadingEngine")[0])
        #connected materials
        materials = str(cmds.ls(cmds.listConnections(shadingEngines), materials = True)[0])
    print cmds.nodeType(materials)
    if cmds.nodeType(materials)=='surfaceShader':
        contourControl=cmds.attrControlGrp("contourControl",edit= True,attribute=shadingEngines+'.miContourWidth')
    else:
        contourControl=cmds.attrControlGrp("contourControl",edit= True,attribute=shadingEngines+'.miContourWidth')


cmds.window( title='Contour Widths' )
cmds.columnLayout()
cmds.attrControlGrp("contourControl",attribute='initialShadingGroup.miContourWidth', l='Contour Width' )
cmds.scriptJob(parent="contourControl",e=["SelectionChanged","update()"])
cmds.showWindow()

what else did i blew it up…

Like I said, there’s nobody receiving the return value from the callback script. You need to either (a) make sure the callback script has a way of knowing the absolute path of the control it’s supposed to update or (b) have the callback be a member function inside a class so the info is available when the callback fires.


import maya.cmds as cmds

class SelectedWindow(object):
    '''
    Creates a window which always displayes the current selection
    
    @note: this is an example illustrating how to set up the callbacks - you would want to use a SelectionConnection instead for real work
    '''
    def __init__(self):
        self.Window = None

    def _create_gui(self):
        self.Window  = cmds.window();
        self.Form = cmds.formLayout(width=208, height=32)
        self.Field = cmds.textField(w = 200, editable=False)   
        af = []
        for side in ['top', 'left', 'bottom', 'right']:
            af.append(  (self.Field, side, 4) )    
        cmds.formLayout(self.Form, e=True, attachForm = af) 

    def show(self):
        self._create_gui()
        cmds.showWindow(self.Window)
        cmds.scriptJob (parent = self.Window, e=['SelectionChanged', self.callback])
        # note that the callback is passed as an object, not a string
        # and since it is a member of the class, it 'knows' which window / controls to work on
        
        
    def callback(self, *args):
        cmds.textField(self.Field, e=True, text=", ".join(cmds.ls(sl=True) or []))
        
    

t = SelectedWindow()
t.show()

You could achieve the same thing by, say, stuffing the control to edit into a globabl variable – but this is much neater and easier to maintain / debug.

dont know how repost happened…

well in your example you have textfield whose value you set to 0 or nothing but i am using attrControlGrp that must be supplied with attribute so when it is initiated on scriptJob it doesnt get updated even if in the callback method has edit and new attribute specified based on selection… I have tried implementing as per what you said but it doesnt get upated, see and if u test i have put it in your example


import maya.cmds as cmds

class SelectedWindow(object):
    '''
    Creates a window which always displayes the current selection
    
    @note: this is an example illustrating how to set up the callbacks - you would want to use a SelectionConnection instead for real work
    '''
    def __init__(self):
        self.Window = None
        self.materials="lambert1"
        self.shadEngine="initialShadingGroup"

    def _create_gui(self):
        self.Window  = cmds.window();
        self.Form = cmds.formLayout(width=208, height=32)
        self.Field = cmds.textField(w = 200, editable=False)
        self.Cntrl=cmds.attrControlGrp( attribute=self.shadEngine+'.miContourWidth' )  
        af = []
        for side in ['top', 'left', 'bottom', 'right']:
            af.append(  (self.Field, side, 4) )    
        cmds.formLayout(self.Form, e=True, attachForm = af) 

    def show(self):
        self._create_gui()
        cmds.showWindow(self.Window)
        cmds.scriptJob (parent = self.Window, e=['SelectionChanged', self.callback])
        # note that the callback is passed as an object, not a string
        # and since it is a member of the class, it 'knows' which window / controls to work on
        
        
    def callback(self, *args):
        shapes = cmds.ls(sl = True, o = True, dag = True, s = True)
        if len(shapes)>0:
            
            self.shadEngine = str(cmds.listConnections(shapes, type ="shadingEngine")[0])
             #connected materials
            self.materials = str(cmds.ls(cmds.listConnections(self.shadEngine), materials = True)[0])
        cmds.textField(self.Field, e=True, text=", ".join(cmds.ls(sl=True) or []))
        self.Cntrl=cmds.attrControlGrp(self.Cntrl, edit=True, attribute=self.shadEngine+'.miContourWidth' ) 
        
        
    

t = SelectedWindow()
t.show()

how should I stuff it in the control to edit into the global // if u mean where i have declared global variables under where I have done import maya.cmds…

i did knew i wasn’t doing anything wrong wen i posted second time as your example is how i implemented in the full code of what this was a part of.

wen i replaced the attrControlGrp with attrFieldSliderGrp it worked… i dont kknow why all i changed is by this change… now only you can tell me why it doesnt work with attrControlGrp but works with attrFieldSliderGrp…?

no idea there. Perhaps attrControlGroup doesn’t rebind when you edit the attribute value? The docs also say ‘Some types of attributes are not supported’

You could setParent to the containing form, delete the existing control, and create a new one in the callback

yea i read on docs too but I never expect that could be the unexplained reason , I shouldnt have tried when i read about it 3-4 days back it could have saved my lots of time… thanks a lot man…

PS:forgot to mention this was for the wheel