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
    • Register
    • Register
    • Login

    how is it possible to check if the object is being "opened"? with python

    Cinema 4D SDK
    python r20 r19 r21
    3
    11
    1.6k
    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.
    • CairynC
      Cairyn
      last edited by

      Use GeListNode.GetNBit(bit) to access the bitfield for the flags. Then check for the bit NBIT_OM1_FOLD, NBIT_OM2_FOLD, NBIT_OM3_FOLD, NBIT_OM4_FOLD, depending on which object manager you're in.

      Note that there are 4 possible object managers, and the opening status can be different for each, so there are 4 different bits to control the status. The difficulty here is that C4D's API does not tell you what OM you're currently in (C4D does not provide a lot of control of the windows...), so worst case you need to have 4 different scripts if you are regularly working with all OMs. (If you only have the first OM open, the point is moot.)

      (I normally don't link back to my own page but incidentally my Python-in-C4D course is in the rough vicinity of handling the bitsets, so you may want to check out https://www.patreon.com/cairyn if you're interested in that kind of thing.)

      pyxelriggerP 1 Reply Last reply Reply Quote 0
      • pyxelriggerP
        pyxelrigger @Cairyn
        last edited by

        @Cairyn said in how is it possible to check if the object is being "opened"? with python:

        GeListNode.GetNBit(bit)

        ohh! this worked thanks!

        but partially ... I would need something to keep checking all the time

        https://i.gyazo.com/97c4e8415eca11cf2e491c3d0ec67f8a.mp4

        CairynC 1 Reply Last reply Reply Quote 0
        • CairynC
          Cairyn @pyxelrigger
          last edited by

          @pyxelrigger I'm not sure what you mean by "all the time". What's the execution context? A script is generally only executed once, precisely when the user calls it. A Python tag is executed every time when the object tree is evaluated.

          You can build a plugin that reacts to messages in the system, and filter those messages, but in general I really don't recommend messing with the execution timepoints and contexts unless it's really really important.

          So, what is the idea, why do you need to check "all the time"?

          1 Reply Last reply Reply Quote 0
          • r_giganteR
            r_gigante
            last edited by

            Hi @pyxelrigger, thanks for reaching out us.

            With regard to your question, I recommend having a look at the GeListNode Manual - it's C++ doc but it's worthy to be read -.
            With regard to your second post instead, I warmly invite you to be more explicative providing a better explanation on you're looking for.

            Cheers, R

            1 Reply Last reply Reply Quote 0
            • pyxelriggerP
              pyxelrigger
              last edited by

              I need to check if it is being opened, and not if it is open

              1 Reply Last reply Reply Quote 0
              • r_giganteR
                r_gigante
                last edited by

                Hi @pyxelrigger thanks for following up.

                With regard to be informed in the console about a hierarchy in the Object Manager being folder or unfolded, there's no performance-penalty-free solution to be implemented. The only and heavily performance-affecting workaround, would be to monitor each entry of the object manager and check its NBit but, as you can imagine, it's cumbersome and could work only with a very limited number of entries in the scene.

                At the same time, I wonder what's the final scope of checking this folded state, cause likely by looking at the problem from a different direction we might come with different, and more effective, solutions. Can you elaborate more on what's the final goal?

                Cheers, R

                1 Reply Last reply Reply Quote 0
                • pyxelriggerP
                  pyxelrigger
                  last edited by

                  08d95bc8-477b-4028-aa81-5b9c5753f68f-image.png

                  basically this is the algorithm that i need

                  1 Reply Last reply Reply Quote 0
                  • r_giganteR
                    r_gigante
                    last edited by

                    Hi @pyxelrigger thanks for the follow-up but actually it doesn't answer to my question of clarifying the final goal.
                    Explaining a bit better your intent will help us to be more effective in helping, because looking at the code it seems like that you expect to delete items from the scene as soon as their hierarchy is unfolded that's weird without a proper context.

                    Thanks, Riccardo

                    1 Reply Last reply Reply Quote 0
                    • pyxelriggerP
                      pyxelrigger
                      last edited by

                      but that's really my intention, delete items from the scene as soon as their hierarchy is unfolded

                      1 Reply Last reply Reply Quote 0
                      • r_giganteR
                        r_gigante
                        last edited by

                        Well @pyxelrigger thanks for clarifying the final scope.

                        Since, as already stated, folding or unfolding a scene entry doesn't generate any valuable message to be intercepted, the sole - brute force - hack you might try to implement in Python would be to implement a MessageData plugin which constantly checks for the folded/unfolded state of the entries in the scene and eventually delete the unfolded one.

                        This approach carries strong performances penalties to the whole Cinema 4D UI because you need to constantly traverse the scene and depending on the scene size this could strongly affect Cinema performances.

                        If there are no further question please mark the thread as solved.

                        Best, R

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