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
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    AddUndo(c4d.UNDOTYPE_CHANGE) not working with doc.ExecutePasses()?

    Cinema 4D SDK
    r21 python
    2
    3
    389
    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.
    • B
      bentraje
      last edited by bentraje

      Hi,

      In this thread, it offers the solution to use the doc.ExecutePasses to "bake" the effect of the PSR when the PSR tag is deleted. My problem is when I inserted the doc.AddUndo(), it does not work (i.e. the object does not move back the original position).

      You can see an illustration of the problem here:
      https://www.dropbox.com/s/c5b3g1f5dr0el7z/c4d183_addundo_with_doc_execute_passes.mp4?dl=0

      As you can see, only the tag creation is undone but not the movement of the object.
      Is there a way around this? Thank you for looking at my problem

      You can see the working code here:

      import c4d
      from c4d import gui
      
      # Select two objects then execute
      def create_constraint():
      
          doc = c4d.documents.GetActiveDocument()
          obj_sel = doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_SELECTIONORDER)
          driven = obj_sel[-1]
          driver = obj_sel[0]
      
          doc.StartUndo()
          tag = c4d.BaseTag(1019364)
          driven.InsertTag(tag)
          doc.AddUndo(c4d.UNDOTYPE_NEW, tag)
      
          tag[c4d.ID_CA_CONSTRAINT_TAG_PSR] = True
          tag[c4d.ID_CA_CONSTRAINT_TAG_PSR_MAINTAIN] = False
      
          tag[10001] = driver
          doc.ExecutePasses(None, True, True, True, c4d.BUILDFLAGS_0)
          doc.AddUndo(c4d.UNDOTYPE_CHANGE, driven)
          
          doc.EndUndo()
          c4d.EventAdd()
      
      
      if __name__=='__main__':
          create_constraint()
      
      1 Reply Last reply Reply Quote 0
      • ManuelM
        Manuel
        last edited by

        Hello,

        As the document says, the UNDOTYPE_CHANGE must be called before the change.

        This seems to work as expected. Let me know.

        import c4d
        from c4d import gui
        
        # Select two objects then execute
        def create_constraint():
        
            doc = c4d.documents.GetActiveDocument()
            obj_sel = doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_SELECTIONORDER)
            driven = obj_sel[-1]
            driver = obj_sel[0]
        
            doc.StartUndo()
            doc.AddUndo(c4d.UNDOTYPE_CHANGE, driven)
            tag = c4d.BaseTag(1019364)
            driven.InsertTag(tag)
            doc.AddUndo(c4d.UNDOTYPE_NEW, tag)
        
            tag[c4d.ID_CA_CONSTRAINT_TAG_PSR] = True
            tag[c4d.ID_CA_CONSTRAINT_TAG_PSR_MAINTAIN] = False
        
            tag[10001] = driver
            doc.ExecutePasses(None, True, True, True, c4d.BUILDFLAGS_0)
            
            
            doc.EndUndo()
            c4d.EventAdd()
        
        
        if __name__=='__main__':
            create_constraint()
        

        Cheers,
        Manuel

        MAXON SDK Specialist

        MAXON Registered Developer

        1 Reply Last reply Reply Quote 2
        • B
          bentraje
          last edited by

          @m_magalhaes

          Oh gotcha. Thanks for the reminder. Totally forgot they UNDOTYPE_CHANGE have a different placement thant UNDOTYPE_NEW

          Thanks again. Have a great day ahead!

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