Best Practice to transfer a variable from another function?

Hi all,

I was wondering what is the recommended way of transferring a variable from a function to another function in python.

In this case I'm using the python generator, and I'd like to transfer a spline object from the main function into the message function to be accessible by a button. I tried using global variables but I get the message:

"ReferenceError: the object 'c4d.SplineObject' is not alive"

Thanks for any insights


there's no real "good practice" and your workflow isn't clear to give you an answer.

It sound normal that when your object is created in the main function, it's not alive in the function you call when pressing the button. The references is passed but the c++ object the reference is pointing to is not alive anymore.

If for example you want your generator to return a cube and add that cube in the scene when you click on a button you should have:

  • one function to create that cube.
  • call that function from main and return the result.
  • call that function when you press the button and insert the result.

But without knowing what the button should do we can't help more.


MAXON SDK Specialist

MAXON Registered Developer

Thanks Manuel, yes that's how I ended up doing it in the end.

I thought it would've been simpler to extract a variable from the main function, since it had already calculated. All I would need is to save the variable somewhere where the button function can read it, so this is where I tried the global variables but it didn't work.