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

    Layers checker

    Cinema 4D SDK
    python s24 sdk
    3
    4
    730
    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.
    • ROMANR
      ROMAN
      last edited by

      Hello guys! Is it real to check everything in layer (objects, materials, tags) and delete layer if its empty?

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

        Hello @roman,

        thank you for reaching out to us. I am assuming that your question is if it is possible to determine if a layer has 'content' attached to it or not.

        Yes, that is possible. It is however more complicated than you might think. Layers are not a data structure that holds scene data but are an attribute that is assigned to scene elements via the ID_LAYER_LINK parameter. So, to determine if a layer "is empty" or not, you must traverse all elements of a scene and check if they are part of that layer not. This is computationally not ideal since you would traverse the scene repeatedly for each layer. You should therefore traverse it once and collect all the layers which are in use and then delete the unused ones. You cannot store simply the base link referenced for that in a ID_LAYER_LINK (at least when you want it to be very robust) but must store the MAXON_CREATOR_ID unique id of the linked layers.

        There is also the problem that many things can be attached to layers, not only objects, materials, and tags, but also shaders and animation tracks for example (and there is probably some stuff I am overlooking). For that you will need a robust scene traversal method which is currently neither provided in the Python or C++ API. You must write your own one, by either just selecting a few cases or by doing it with GeListNode.GetBranchInfo() which is in both cases a non-trivial task, as you must avoid recursion-based stack overflows or in Python the recursion limit of 1000 preventing them.

        There were some posts in the past which will help you, as for example this one which contains code for a simplistic NodeIterator which will yield all objects and tags of a scene when you pass the first object in a document to it, and this which talks about and contains code for retrieving the objects attached to a layer. But for the generic form you are requiring, there are no examples yet. We cannot write this for you, please produce your own code and we will help you along the way when you encounter problems.

        Cheers,
        Ferdinand

        MAXON SDK Specialist
        developers.maxon.net

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

          Beginner solution:
          If you do not need a certain layer you could also implement the call comand "Delete unused layers"
          Its not pretty but beats any convulated self written code if it is not called to often.

          c4d.CallCommand(100004760) # Remove unused layers

          cheers
          mogh

          ROMANR 1 Reply Last reply Reply Quote 1
          • ROMANR
            ROMAN @mogh
            last edited by

            @mogh I didn't know about this function 🤦
            @ferdinand Thank you a lot for your detailed response. I will chek posts which you recommended

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