Scenario:
I’ve created a scriptJob which triggers a function called checkSel(), and it does this on SelectionChange. It is a function which checks a certain condition (if a mesh is selected) and then returns data from the mesh.
And since the user might already have a mesh selected upon starting my tool (thus, avoiding triggering the scriptJob) I have to run checkSel() manually in the code. Anyway, my problem is the returned variables comming from checkSel. I don’t know how to basicly make the scriptJob call this function and have a set of variables overwritten. Maybe the code explains it better:
# Tool functions
# Tool UI
# Display the window
pm.showWindow( window )
# Selection check and core variable creation
varA, varB, varC = checkSel()
# Create scriptJob
pm.scriptJob(
event=["SelectionChanged", lambda *args: varA, varB, varC = checkSel()], ## WARN: Syntax Error
parent=window
toolUI()
Works: Running my tool with a mesh selected (and by avoiding the syntax error in the scriptJob by just calling checkSel without trying to assign the returned data to variables)
Doesn’t work: Running my tool without a mesh selected, then selecting a mesh, and running a core feature.
Why it doesn’t work: Core feature requires varA, varB and varC to be updated by the scriptJob
So now I’m sitting here actually considering making varA, varB and varC into global variables and just avoid passing variables around. But global variables are evil (or that’s pretty much what everyone says!).
Best approach here?