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

    How to get the object newly added in current scene?

    Cinema 4D SDK
    s26 2023 python
    3
    9
    1.2k
    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

      Hi plugincafe~
      I want to get the object newly added in to current scene in my Dialog plugin and update something in my dialog.

      For example:
      Add something in the scene(like a null object), how do i get this object? and how to get this Message?

      I find c4d.EVMSG_CHANGE in SDK and i can get some document changed message in CoreMessage. But I don't know what to do next.

      www.boghma.com

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

        @gheyret

        Maybe you should check this How to change light param

        @ferdinand has a great explain there

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

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

          @dunhou
          Cool man ! That's what i want !
          I actually thought about traverse everything in the scene, but I felt it would be a waste. for example, if there were a lot of objects in the scene, so I think if there was another way to do that. But based on your post, that's the only way to do.
          Anyway , thank you and @ferdinand
          Cheers~🥂

          www.boghma.com

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

            Hello @gheyret,

            thank you for reaching out to us and thank you @Dunhou for providing an answer. Yes, in the end you might have to track things over their UUID. This is however usually only the case when you must associate data with the newly added things. If not, it is often cheaper to just rebuild your GUI on every EVMSG_CHANGE. Helpful might here be also:

            • Dynamic Dialog GUI: What you probably want to do entails rebuilding a dialog dynamically. This example demonstrates how to do this in a simplified manner.
            • Narrow down EVMSG_CHANGE events: Often it is desirable to narrow down EVMSG_CHANGE events to cases where actually something meaningful has changed. The topic shows this at the example of material states being cached. This demonstrates also the usage uf UUID to identify cache contents as well as storing GUI data abstractly so that it persists over reallocation boundaries.

            Cheers,
            Ferdinand

            MAXON SDK Specialist
            developers.maxon.net

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

              Hi @ferdinand , thanks to your reply.
              There is another quession; the basic property (like Name, Viewport visibility, Enabled, e.t.c) of object is not in the data container? I mean the c4d.BaseContainer returned by c4d.BaseList2D.GetData()

              www.boghma.com

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

                Hey @gheyret,

                The name of a node is certainly contained in the data container, when it comes to visibility, I assume you mean render/viewport visibility, and they are also parameters. With "Enabled" i assume you mean the green check-mark of generators, and this is also a parameter.

                >>> Cube[c4d.ID_BASELIST_NAME]
                'Cube'
                >>> Cube[c4d.ID_BASEOBJECT_VISIBILITY_EDITOR]
                2
                >>> Cube[c4d.ID_BASEOBJECT_VISIBILITY_RENDER]
                2
                >>> Cube[c4d.ID_BASEOBJECT_GENERATOR_FLAG]
                1
                

                Remember that you can simply drag and drop parameters to the console to find out their ID. All these parameters can be found in the "Basic" tab.

                3f8c2325-1690-4342-bcb5-3e03074849bc-image.png
                When you mean the NBIT flags for hiding things, as for example NBIT_OHIDE to hide an object or tag in the Object Manager, they are indeed not part of the data container because they are flags.

                Cheers,
                Ferdinand

                MAXON SDK Specialist
                developers.maxon.net

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

                  @ferdinand
                  I mean i Get the Object Data using BaseList2D.GetData() and SetDatato another object, it's only change the parameter of "Object" Tab in Attributes Manager.
                  Hera is a exmaple:

                  from typing import Optional
                  import c4d
                  
                  doc: c4d.documents.BaseDocument  # The active document
                  op: Optional[c4d.BaseObject]  # The active object, None if unselected
                  
                  def main() -> None:
                      new = doc.GetFirstObject()
                      old = new.GetNext()
                      
                      old.SetData(new.GetData())
                      
                      c4d.EventAdd()
                  
                  if __name__ == '__main__':
                      main()
                  

                  Before run the script
                  01.png

                  After run the script
                  02.png

                  As you can see, the object name, visibilitys and display color is not changed by SetData

                  www.boghma.com

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

                    Hello @gheyret,

                    my apologies, yes, these parameters are not part of the BaseContainer data container, your initial question was quite clear about that, I just quickly answered the question before I left yesterday and overlooked that aspect.

                    But you could create a tuple to copy these parameters over because other than in the C++ layer, we do not have to worry much about data types with __get/setitem__, i.e., the bracket syntax.

                    Cheers,
                    Ferdinand

                    Result:
                    2b683952-c111-4e7c-a101-271237245800-image.png

                    Code:

                    from typing import Optional
                    import c4d
                    
                    doc: c4d.documents.BaseDocument  # The active document
                    
                    PID_COLLECTION: tuple[int] = (
                        c4d.ID_BASELIST_NAME,
                        c4d.ID_BASEOBJECT_VISIBILITY_EDITOR,
                        c4d.ID_BASEOBJECT_VISIBILITY_RENDER,
                        c4d.ID_BASEOBJECT_GENERATOR_FLAG,
                        c4d.ID_BASEOBJECT_USECOLOR,
                        c4d.ID_BASEOBJECT_COLOR,
                        )
                    
                    def main() -> None:
                        """
                        """
                        new = doc.GetFirstObject()
                        old = new.GetNext()
                        
                        old.SetData(new.GetData())
                        for pid in PID_COLLECTION:
                            new[pid] = old[pid]
                        
                        c4d.EventAdd()
                    
                    if __name__ == '__main__':
                        main()
                    

                    MAXON SDK Specialist
                    developers.maxon.net

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

                      Hi @ferdinand , I get it ! Thanks again to your reply!

                      www.boghma.com

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