2017-03-22 9 views
0

質問があります...私はPythonでスクリプトを作成しています...値を挿入するスライダがいくつかありますが、値を1つにしたい関数、他の関数へのいくつかの他の...私は別の単一の関数(作業)のすべての関数を渡すことができるスクリプトは...そしてコメントで私はそれが私が必要なもののために働いたと思った行しかし、それはしません。一度に異なる関数に異なる値を渡す方法

import maya.cmds as cmds 

#def function1(value): 
def function1(value1,value2): 
    print(value1) 

def function2(value): 
    print(value) 

def createUI(): 
    cmds.window("Window") 
    cmds.columnLayout(adjustableColumn=True) 
    value1 = cmds.intSliderGrp(label='number of moons', minValue=4, maxValue=20, value=12, field=True) 
    value2 = cmds.intSliderGrp(label='Distance from parent to child', minValue=5, maxValue=40, value=20, field=True) 

    #cmds.button(label = "OK", command = lambda *args: function1(cmds.intSliderGrp(value1, query=True, value=True)),function2(cmds.intSliderGrp(value2, query=True, value=True))) 
    cmds.button(label = "OK", command = lambda *args: function1(cmds.intSliderGrp(value1, query=True, value=True), cmds.intSliderGrp(value2, query=True, value=True))) 
    cmds.showWindow() 

createUI() 

答えて

1
import maya.cmds as cmds 
from functools import partial 

# Dictionnary to store the ui important variables 
uiDic = {} 

#def function1(value): 
def function1(value1,value2): 
    print(value1) 
    print(value2) 
# another normal function 
def function2(value): 
    print(value) 

# save the slider value to the dic 
def setSliderUiDic(sliderName, *args): 
    entryName = '{}_value'.format(sliderName) 
    uiDic[entryName] = getSlider(sliderName) 

# get any slider value (in order to refresh) 
def getSlider(nameCtrl): 
    value = cmds.intSliderGrp(nameCtrl, query=True, value=True) 
    return value 

# create a def that combine multiple function to ui purposes 
def ui_func(*args): 
    slider1Value = uiDic['{0}_value'.format(uiDic['value1'])] 
    slider2Value = uiDic['{0}_value'.format(uiDic['value2'])] 
    function1(slider1Value, slider2Value) 
    function2(slider1Value) 

def createUI(): 
    #windowtest 
    if cmds.window("wintest", q=True, ex=True): 
     cmds.deleteUI("wintest") 
    cmds.window("wintest") 
    #layout 
    cmds.columnLayout(adjustableColumn=True) 
    #create the slider and store it to dic 
    uiDic['value1'] = cmds.intSliderGrp(label='number of moons', minValue=4, maxValue=20, value=12, field=True) 
    # Add a function to update the value of the slider 
    cmds.intSliderGrp(uiDic['value1'], e=True, cc=partial(setSliderUiDic, uiDic['value1'])) 
    # Store the default value 
    setSliderUiDic(uiDic['value1']) 

    #Do the same thing to slider 2 
    uiDic['value2'] = cmds.intSliderGrp(label='Distance from parent to child', minValue=5, maxValue=40, value=20, field=True) 
    cmds.intSliderGrp(uiDic['value2'], e=True, cc=partial(setSliderUiDic, uiDic['value2'])) 
    setSliderUiDic(uiDic['value2']) 

    # create a UI function that group multiple functions 
    cmds.button(label = "OK", command = ui_func) 
    cmds.showWindow() 

createUI() 
関連する問題