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

    c4d.EventAdd() is not working

    Bugs
    python 2023
    6
    9
    2.1k
    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.
    • gheyretG
      gheyret
      last edited by ferdinand

      There is a problem;
      When i try to add some object in the scene and add c4d.EventAdd() , the object added correctly and viewport is refreshed but nothing happed in Object Manager, i need to click some button to refresh the object manager.

      import c4d
      
      def main() -> None:
          doc.InsertObject(c4d.BaseObject(c4d.Onull))
          c4d.EventAdd()
      
      if __name__ == '__main__':
          main()
      

      Is that BUG or something changed ?
      Oh, i used Cinema 4D 2023.2.1 version.

      www.boghma.com

      gheyretG 1 Reply Last reply Reply Quote 0
      • gheyretG
        gheyret @gheyret
        last edited by gheyret

        I get a solution:
        1.Create a material and insert it
        2.EventAdd()
        3.delete the material
        code like this:

        mat = c4d.Material(5703)
        doc.InsertMaterial(mat)
        c4d.EventAdd()
        mat.Remove()
        

        But this is not the correct way

        www.boghma.com

        1 Reply Last reply Reply Quote 0
        • M
          m_adam
          last edited by m_adam

          Hi @gheyret, thanks a lot for the report, this was indeed broken in 2023.1, then it got fixed in 2023.2, and I can't reproduce your issue in 2023.2.1. May I ask on which OS are you?

          But as a workaround (at least for the bug that was present in 2023.1) you can do

              null = c4d.BaseObject(c4d.Onull)
              doc.InsertObject(null)
              null.SetBit(c4d.BIT_ACTIVE)
              c4d.EventAdd()
          

          Cheers,
          Maxime.

          MAXON SDK Specialist

          Development Blog, MAXON Registered Developer

          gheyretG DunhouD 2 Replies Last reply Reply Quote 0
          • gheyretG
            gheyret @m_adam
            last edited by

            Hi @m_adam I am using Windows 10

            www.boghma.com

            1 Reply Last reply Reply Quote 0
            • DunhouD
              Dunhou @m_adam
              last edited by

              @m_adam
              Hey , I think it lasted for a long time, sometimes I just use cinema built-in button to create a Object like a Cube, it will also didn't refresh.and maybe add few objects can fix that.I use latest windows 11 and R2023.2.1 but I think early version I have this problem either, and null.SetBit(c4d.BIT_ACTIVE) I will try it later , but the Object didn't show in OM at all , this bug usually happend in a new document

              https://boghma.com
              https://github.com/DunHouGo

              ferdinandF 1 Reply Last reply Reply Quote 0
              • ferdinandF
                ferdinand @Dunhou
                last edited by ferdinand

                Hey @everyone,

                Thank you for reporting this bug. It is the known bug ITEM#431586 Object Manager Update Error on Object Insertion from Script. The bug has been fixed, but the fix has not yet been shipped.

                At least when I investigated the shipped code of 2023.2.1, the code which fixes the issue, was not there. This might have been an integration error. I can however certainly confirm that the bug still does exist in 2023.2.1 (Build 2023.CL401745.844493561) Win and that the code has not been shipped.

                The issue will be fixed in an upcoming version of Cinema 4D. In the meantime, the workaround suggested by Maxime can be used. Find below the full bug report for clarity.

                Cheers,
                Ferdinand

                Bug Report:

                The Object Manager (OM) is not being updated in some cases when an object is being inserted from a Python script, resulting in the script to run, the object being part of the new scene graph, but the OM not showing this new state.
                
                Something with the event chain seems to be going wrong here. The script does call EventAdd() but in the problem cases it is ignored, and other ways to force an event (as for example clicking into the interface somewhere), do not work either. Only adding an object manually will make Cinema 4D "snap out of it".
                
                Tested in: S26.107, 2023.0.0, 2023.1.0 (all behave the same)
                I have also included a GIF which showcases the problem, as it is a bit tricky to reproduce and explain.
                
                Steps to reproduce:
                1. Switch to the Script layout.
                2. Copy and paste the attached script.
                3. Run the script a couple of times -> Result A
                4. Select all newly created null objects in the Object Manager and delete them.
                5. Run the script again multiple times -> Result B
                6. Change the last line in the script from "print (1)" to "print (12)"
                7. Run the script again multiple times -> Result C
                8. Manually insert an object from the tool bar into the document -> Result D
                
                Result A:
                a. A new null object appears in the OM
                b. Prints "1" to the console
                
                Result B:
                a. A new null object does NOT appear in the OM
                b. Prints "1" to the console
                
                Result C:
                a. A new null object does NOT appear in the OM
                b. Prints "12" to the console
                
                Result D:
                a. All previously added objects now appear in the OM (all the nulls we added)
                b. The object we added manually does appear in the OM
                c. On all further script executions, Cinema will now behave correctly again (until we trigger the problem again).
                
                
                There is also at least one alternative way the same behaviour can be induced:
                
                1. Switch to the Script layout.
                2. Copy and paste the attached script.
                3. Run the script a couple of times -> Result A
                4. Rename the variable "node" to "nodea".
                5. Run the script again multiple times -> Result B
                
                It his however less reliable in reproducing the problem, and one might have to change the code multiple times. But it is possible to trigger the problem by just changing variable names and without touching the scene graph as for example deleting all objects.
                

                Code:

                import c4d
                
                doc: c4d.documents.BaseDocument # The active document.
                
                def main() -> None:
                    node = c4d.BaseObject(c4d.Onull)
                    if not isinstance(node, c4d.BaseObject):
                        raise MemoryError()
                
                    doc.InsertObject(node)
                    c4d.EventAdd()
                    print (1)
                
                if __name__ == '__main__':
                    main()
                

                MAXON SDK Specialist
                developers.maxon.net

                1 Reply Last reply Reply Quote 0
                • P
                  pim
                  last edited by

                  Aha, good to know.
                  I had the same issue, but now I know what to do.

                  1 Reply Last reply Reply Quote 0
                  • T
                    thomas
                    last edited by

                    slightly worrying that I hit this bug right away after my first 30 minutes to scripting in c4d.

                    ferdinandF 1 Reply Last reply Reply Quote 0
                    • M m_adam referenced this topic on
                    • ferdinandF
                      ferdinand @thomas
                      last edited by

                      Hey everyone,

                      The issue has been fixed and verified in an internal build. It will be shipped with one of the builds of the next major update (i.e., it will not make it into 2023.x.y anymore). Beta testers can already make use of the change in the most recent beta build.

                      Cheers,
                      Ferdinand

                      MAXON SDK Specialist
                      developers.maxon.net

                      1 Reply Last reply Reply Quote 0
                      • maxonM maxon moved this topic from Cinema 4D SDK on
                      • First post
                        Last post