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

    Get previous position of object

    Scheduled Pinned Locked Moved PYTHON Development
    6 Posts 0 Posters 446 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 15/02/2013 at 00:33, xxxxxxxx wrote:

      Hello All, I wonder how it is possible to get the previous position of an Object after I moved it.
      I thought I could do an undo and check the Position and than compare it. But it is returning always the current position. 
      Any Clues? Thank you in advance.

      Here is the Code I tried:

      selec = doc.GetActiveObject()
          newpos=selec.GetAbsPos()
          c4d.CallCommand(12105) # Undo
          c4d.EventAdd()
          
          oldpos=selec.GetAbsPos()
          
          
          print "newpos:", newpos
          print "oldpos:", oldpos

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

        On 15/02/2013 at 01:11, xxxxxxxx wrote:

        Hi holgar,

        it depends. It depends on how your code is executed: Script Manager, Python Tag/Genreator/XPresso
        Node?

        When you're not in the Script Manager, you shouldn't perform an undo, or any CallCommand()
        actually. When you are, it's fine to perform an undo, but can you assure the last action you've done
        is moving the object? It is actually impossible to grab the previous position of an object from the
        Script Manager since you can not be 100% sure the last undo-action has moved the object, nor
        doing an undo for this is a nice approach.

        From an Expression (Python Tag/Generator/XPresso Node), you can store the position of the object
        in a global variable and read it out another time your code is executed.

        -N

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

          On 15/02/2013 at 02:58, xxxxxxxx wrote:

          Hi Niclas, Thanks for your respond.
          I want to execute this in the Scriptmanager. But somehow I get not the OldPosition after an Undo. It is always returning the current Position. Well, to be sure I have moved the Object I could ask if Oldpos=newpos. So I would know I have moved the Object.

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

            On 15/02/2013 at 04:21, xxxxxxxx wrote:

            Interesting. I can't get it to work properly, too.

            import c4d
              
            old_pos = op.GetAbsPos()
            doc.DoUndo(False)
            new_pos = op.GetAbsPos()
              
            print old_pos
            print new_pos
            print '~' * 20
              
            c4d.EventAdd()
            

            When I move the object in the editor (using mouse-drag) and execute the script, I get two
            times the same position. When I set the position of the object in the Attribute Manager and
            execute the script, I get the expected result: two different vectors.

            Weird.. ^_^

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

              On 15/02/2013 at 04:34, xxxxxxxx wrote:

              You are right. Change values in the AM will return two diferent Vectors...smells like a Bug?

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

                On 15/02/2013 at 12:54, xxxxxxxx wrote:

                You are looking for a previous state of an -un- animated object?
                Else AnimateObject() would be the way.

                Cheers
                Lennart

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