On 15/01/2015 at 12:49, xxxxxxxx wrote:
Hi there, I'm scripting within the new R16 interaction tag & I have 1 question : How can I pass variables between the pre-defined functions ?
In a normal script, I would do this via the main() function, like this:
def func1() :
var1 = "whatever"
return var1
def func2(var1) :
print("Do something with " + var1)
return
def main() :
var1 = func1()
func2(var1)
But in the interaction tag, there is no main()
What I want to do is:
- Test some conditions in mouseDown() because this executes only once on initial click
- pass the results of the tests to mouseDrag()
- execute some actions only if the conditions were met
What should my approach be ? Should I define a global variable & use that ?
Here is my very early skeleton code with just a few print statements, I want to pass the variable poly_sel to mouseDrag() :
#Tweak tag script
#Predefined global variables : tag, op, proxy, doc, thread, qualifier
import c4d
from c4d import gui
def mouseDown() :
#Initialization/start tweak code goes here
print("Mouse Down")
poly_sel = tag[c4d.INTERACTIONTAG_POLYINFO_SELECTIONTAG]
if poly_sel:
name = poly_sel.GetName()
if name == "Jaw Area":
print("Polygon Selection Named : Jaw Area")
else:
print("No Selection Tag")
def mouseDrag() :
#Main code loop for when the mouse button is down and tweak is occuring happens here
print("Dragging...")
def mouseUp() :
#Code for what happens when the mouse button is released goes here
print("Mouse Up")