python maya, function call 2 functions, force to run both
Question: I made a windowUI with a button to run 2 functions so I defined a new function
to run the other 2

    
    
    def addSlider_splitLoop():
        addSlider()
        splitLoop()
    
    mc.button(label ='Combo' , command = 'addSlider_splitLoop()' )
    

when the button is pressed, only 1 function works:

  * when nothing is selected the command only runs the addSlider() function,

  * when the polygon loop is selected the command only runs the splitLoop() function

which actually make sense, but does not help me, and changing the order ot the
functions also does not help

I want to force it to run both functions, how can I do this?

actually the best thing would be to have the addSlider() to run only when the
splitLoop() works, but I'm a real beginner and I have no clue how to do
this... force to run both functions might be a dirty solution but is enough
for me at the moment

this is the full code anyway (the combo button is just for testing)

    
    
    import maya.cmds as mc
    
    def addSlider_splitLoop():
            addSlider()
            splitLoop()    
    
    
    
    
    def addSlider():
            mc.floatSliderGrp( minValue = 1.00 , maxValue = 99.00 , value = 50.00 , field = True )
    
    def splitLoop():    
            mc.ConvertSelectionToContainedEdges()
            mc.polySplitRing(sma = 180 , wt = 0.5)
            mc.polyDuplicateEdge(ch = True , of = loopDistance() )
            #addSlider()
    
    
    
    
    def doubleLoop():
            mc.ConvertSelectionToContainedEdges()
            mc.polySplitRing(sma = 180 , wt = 0.5)
            mc.polyDuplicateEdge(ch = True , of = loopDistance() )
            mc.polyDelEdge(e = False, cv = True,)
            #addSlider()
    
    def loopDistance():
            distance =  mc.floatSliderGrp('LoopDistanceValue' , query = True, value = True)
            convertedDistance = distance / 100
            return convertedDistance    
    
    
    
    def splitLoopUI():
    
            if mc.window('splitLoopUI' , exists = True):
                mc.deleteUI('splitLoopUI')
    
            mc.window('splitLoopUI')
    
            mc.frameLayout( label='                            set loop distance')
            mc.floatSliderGrp('LoopDistanceValue' , minValue = 1.00 , maxValue = 99.00 , value = 50.00 , field = True )    
    
            mc.button(label ='Triple Loop' , command = 'splitLoop()' ) 
            mc.button(label ='Double Loop' , command = 'doubleLoop()' )
            mc.button(label ='Combo' , command = 'addSlider_splitLoop()' )
    
            mc.text( label=' +   edit loop distance   + ')
    
            mc.scrollLayout( 'scrollLayout' )
            mc.columnLayout( adjustableColumn=True )
    
    
            mc.showWindow('splitLoopUI')
    splitLoopUI()
    


Answer: A couple of things going on here.

  1. Don't call the scripts as strings -- that's a recipe for wierdness down the road. Pass the function objects instead, as in @Dr.Weeny's example. It's more reliable and actually faster as well. [More here](http://techartsurvival.blogspot.com/2014/04/maya-callbacks-cheat-sheet.html)
  2. In your posted code `addSlider()` doesn't do any work to get the currently active GUI object -- depending on when it runs that slider could be showing up anywhere -- in the channel box, in some other window, or it could be failing. This is probably why it seems like the function isn't running: you're just not spotting the new slider wherever it ends up. Try adding a debug print.
  3. if you want to run `addSlider()` after other commands, the simplest thing to do is probably to have all of the tool commands return a value indicating that they have succeeded or failed:
    
        def splitLoop():    
        try:
            mc.ConvertSelectionToContainedEdges()
            mc.polySplitRing(sma = 180 , wt = 0.5)
            return mc.polyDuplicateEdge(ch = True , of = loopDistance() )
         except:
             return None
    
    def addSlider_splitLoop():
        if splitLoop():
            addSlider()    
    

