Access to a variable returned by a function launched by a button


#1

Hello !

I have a simple python/pymel script that helps the user to copy the value of selected attributes in the channel box and paste them after the user would have selected another object and the same or other attributes.

There are 2 buttons, one to copy the attributes, one to paste them.
The first button launches a function that creates a list of the values of those selected attributes.
The second button is supposed to launch a function to paste those values. The problem is that I can’t find a way to access to the list I created with the first function.

Here is my code:

import pymel.core as pm
import pymel.core.windows as pw




#copy the attributes
def copy_attr(*args):

    attrs = getSelectedChannels() #function to get the attributes names from the selection in the channel box
    attrsValues = copyAttrs(attrs)   #function to copy their values in a list
    return attrsValues                       #at this point, my list is ok


#paste
def paste_attrs(attrsValues,*args):

    attrs = getSelectedChannels()
    pasteAttrs(attrs,attrsValues)


#############################################################
#UI

#check if windows already exists
if pw.window(windowName, exists = True):
    pw.deleteUI(windowName)

#window creation & definition
myWindow = pw.window(windowName, t  = scriptName + " " + scriptVersion , w=100, h=100,)
pw.columnLayout(adj = True, columnAlign = "center")
pw.separator(h = 20)
pw.text(titleWindow)
pw.separator(h = 20)


pw.text("First, select the attributes you want")
pw.text("to copy from the channel box\n")
pw.text("Then, select the attributes in the channel  ")
pw.text("box where you wantto paste them\n")
pw.text("Finally, choose paste or reversed paste")
pw.separator(h = 20)

pw.gridLayout( numberOfColumns=3, cellWidthHeight=(110, 25) )

attrValues = pw.button(l = button_copy,width = 60, command = pm.Callback(copy_attr)) #attrValues doesn't correspond to the attrsValues list the function returned, that's where it fails
pw.button(l = button_paste,width = 60, command = pm.Callback(paste_attrs, attrValues )) 
pw.separator(h = 10)


pw.showWindow(myWindow)

If you have any idea of how I should deal with that… it would be much appreciated ! Thank you for your help !