Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    Best Practice to transfer a variable from another function?

    Cinema 4D SDK
    python sdk
    2
    3
    467
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • orestiskonO
      orestiskon
      last edited by

      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

      1 Reply Last reply Reply Quote 0
      • ManuelM
        Manuel
        last edited by

        hi,

        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.

        Cheers,
        Manuel

        MAXON SDK Specialist

        MAXON Registered Developer

        1 Reply Last reply Reply Quote 1
        • orestiskonO
          orestiskon
          last edited by

          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.

          1 Reply Last reply Reply Quote 0
          • First post
            Last post