Comme vous avez deja pu le remarquer, Python maya accepte pas d'arguments pour les callback fonctions des UI, par exemple ce qui suit le 'command' d'un bouton...
Faire ceci n'est pas possible:
bt1 = cmds.button(l = 'test1', c = maFonction(monArgument))
La maniere la plus simple de contourner le probleme et de faire appel a la fonction functools.partial. Pour executer une fonction a l'aide de functools.partial:
functools.partial(maFonction, monArgument)
Un petit exemple concret:
import maya.cmds as cmds from functools import partial def selType(none = None, types = None): t = cmds.ls(type = types) cmds.select(t) if cmds.window('partialEx', q= True, ex = True): cmds.deleteUI('partialEx') win = cmds.window('partialEx') lay = cmds.columnLayout() bt1 = cmds.button(l = 'test1',p = lay, c = partial(selType, types = 'mesh')) bt2 = cmds.button(l = 'test2',p = lay, c = partial(selType, types = 'nurbsSurface')) cmds.showWindow(win)
Notez que functools.partial demande un argument supplementaire, ici j'ai ajouté none = None. Si la fonction est dans une class alors le self de la class fera l'affaire.
Aucun commentaire:
Enregistrer un commentaire