Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python 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
    • Recent
    • Tags
    • Users
    • Login

    Variable set to an object not updating

    Scheduled Pinned Locked Moved PYTHON Development
    4 Posts 0 Posters 356 Views
    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.
    • H Offline
      Helper
      last edited by

      On 12/07/2014 at 18:07, xxxxxxxx wrote:

      I tracked an annoying bug down to a simple example that, hopefully someone can help me with.

      I'm setting a global variable to an object like this with a button:

      gl_active_rig = doc.GetActiveObject()
      

      Then, I physically move the object in the viewport.

      Then I press another button that prints out the position by doing this:

      print gl_active_rig.GetMg().off
      

      Okay, it works fine.  It prints the correct location.

      Now press undo, and the objects jumps back to it previous location.
      Press the button to print the location again and it doesn't print the 'undone' location.
      It is still printing the moved location.

      If I click on the object in the viewport, and then press the button to display the location again, it prints the 'undone' location properly.

      What is going on?

      1 Reply Last reply Reply Quote 0
      • H Offline
        Helper
        last edited by

        On 13/07/2014 at 05:57, xxxxxxxx wrote:

        You still have the reference to the object in the undo-stack. Get it again with doc.GetActiveObject().

        -Niklas

        1 Reply Last reply Reply Quote 0
        • H Offline
          Helper
          last edited by

          On 13/07/2014 at 10:09, xxxxxxxx wrote:

          The problem is, in my actual plugin, it is no longer active.
          That's why I'm storing it.

          And since Objects in C4D can have identical names, if they are in different parental hierarchies, I can't search by name to find the object.

          So how do I 'refresh' the reference?

          Thanks

          1 Reply Last reply Reply Quote 0
          • H Offline
            Helper
            last edited by

            On 18/07/2014 at 10:58, xxxxxxxx wrote:

            Per-Anders, on another forum solved it, although he warned base containers are slow.

            For others who don't know how to do this, here's what I did:

            # At module level
            gl_bc_active_rig = c4d.BaseContainer()    
              
            # Then in a function to set it:
            global gl_bc_active_rig
            obj = ?  #whatever you want, a null perhaps.
            gl_bc_active_rig.SetData(0, obj)
              
            # Then in any other function when valid data is needed...and when isn't it?, call this function
            def GetActiveRig() :
                global gl_bc_active_rig    
                doc = documents.GetActiveDocument() 
                return gl_bc_active_rig.GetLink(0, doc)
            

            That solved the problem.

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