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

    Xpresso & Pyhton - Convert Link List (Hierarchy Node) to In-/Exclusion

    Cinema 4D SDK
    python 2024
    2
    8
    1.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.
    • H
      hoffwerr
      last edited by

      Hi there!
      I'm trying to convert the output of a Hierarchy Node into an In-/Exclusion list.
      I've done quite a bit of research to try to figure this one out but I'm honestly not a coder and I couldn't figure it out at all.

      This is kind of of what I'm trying to do.
      Cinema_4D_6tlp4ejKfU.png

      Any change I can get some help on this.

      Thanks!

      i_mazlovI 1 Reply Last reply Reply Quote 0
      • i_mazlovI
        i_mazlov @hoffwerr
        last edited by

        Hi @hoffwerr ,

        Welcome to the Maxon developers forum and its community, it is great to have you with us!

        Getting Started

        Before creating your next postings, we would recommend making yourself accustomed with our forum and support procedures. You did not do anything wrong, we point all new users to these rules.

        • Forum Overview: Provides a broad overview of the fundamental structure and rules of this forum, such as the purpose of the different sub-forums or the fact that we will ban users who engage in hate speech or harassment.
        • Support Procedures: Provides a more in detail overview of how we provide technical support for APIs here. This topic will tell you how to ask good questions and limits of our technical support.
        • Forum Features: Provides an overview of the technical features of this forum, such as Markdown markup or file uploads.

        It is strongly recommended to read the first two topics carefully, especially the section Support Procedures: Asking Questions.

        About your First Question

        Please elaborate on what exactly you're trying to achieve? Why do you need a python node here, wouldn't it be enough using ObjectList node instead? What exactly do you mean by "convert to In-Exclusion list"?

        Please don't be shy to attach a sample project file that shows where you are currently at.

        Cheers,
        Ilia

        MAXON SDK Specialist
        developers.maxon.net

        1 Reply Last reply Reply Quote 0
        • H
          hoffwerr
          last edited by

          Hi @i_mazlov ,

          Thanks for getting back to me about my question. I'm basically trying to auto populate the "Effectors" list in the Group Effector with whatever effectors are child of it. I thought I'd just use a Hierarchy node and somehow plug that in directly in that Effectors with Xpresso but it turned out to be not straight forward as I thought.

          Cinema_4D_VIbt5rICUS.png

          So my idea was to somehow setup a quick python script where it would cycle through the Hierarchy node output and add them all into an In-Exclusion list. I think the ObjectList is exactly the opposite of what I'm trying to do. The Input is an In-Exclusion list while the output is an Object/Instance.

          Not sure what would be the Ideal workflow for something like this.

          1 Reply Last reply Reply Quote 0
          • H
            hoffwerr
            last edited by

            Ok. I did some more research and I think I'm kinda close to figuring this out. I ended up using a Python tag instead.

            import c4d
            
            def main():
                obj = op.GetObject()
                print (obj)
                effectors = obj.GetChildren()
                print (effectors)
                
                GroupList = c4d.InExcludeData()
                GroupList.InsertObject(effectors, 1)
                obj[c4d.MGGROUPEFFECTOR_EFFECTORLIST] = GroupList
                
                c4d.EventAdd()
            

            Seems to work just fine up until adding the selection to the InExcludeData

            <c4d.BaseObject object called Group/Group with ID 1019351 at 1949340925248>
            [<c4d.BaseObject object called Plain.2/Plain with ID 1021337 at 1949342765760>, <c4d.BaseObject object called Plain.3/Plain with ID 1021337 at 1949342765632>, <c4d.BaseObject object called Plain.4/Plain with ID 1021337 at 1949342766400>]
            Traceback (most recent call last):
              File "Python", line 10, in main
            TypeError: argument 1 must be c4d.BaseList2D, not list
            

            I'm getting this error at the bottom with the objects being a "list" instead of "c4d.BaseList2D". Can't seem to figure this one out.

            H 1 Reply Last reply Reply Quote 0
            • H
              hoffwerr
              last edited by

              Ok, I did some more research and found some old topic with a similar problem. This seems to work for me at least. I'm able to get all the child objects and auto add them to the InExcludeData.

              import c4d
              
              def AddHierarchyToInEx(obj, inex) :
                  if obj is None:
                      return
                  while obj is not None:
                      inex.InsertObject(obj, 1)
                      AddHierarchyToInEx(obj.GetDown(), inex)
                      obj = obj.GetNext()
              
              
              def main():
                  obj = op.GetObject()
                  InExData = c4d.InExcludeData()
                  AddHierarchyToInEx(obj.GetDown(), InExData)
                  obj[c4d.MGGROUPEFFECTOR_EFFECTORLIST] = InExData
              
                  c4d.EventAdd()
              
              1 Reply Last reply Reply Quote 0
              • H
                hoffwerr
                last edited by

                This is based from this thread.
                https://developers.maxon.net/forum/topic/10016/13482_python-node-with-hierarchy/4

                But it's unfortunately causing crashes. It seems to be returning every single object under the main object so all the children and grand children, etc. Is there anyway to limit this to just the children ?

                1 Reply Last reply Reply Quote 0
                • H
                  hoffwerr @hoffwerr
                  last edited by

                  @hoffwerr said in Xpresso & Pyhton - Convert Link List (Hierarchy Node) to In-/Exclusion:

                  Ok. I did some more research and I think I'm kinda close to figuring this out. I ended up using a Python tag instead.

                  import c4d
                  
                  def main():
                      obj = op.GetObject()
                      print (obj)
                      effectors = obj.GetChildren()
                      print (effectors)
                      
                      GroupList = c4d.InExcludeData()
                      GroupList.InsertObject(effectors, 1)
                      obj[c4d.MGGROUPEFFECTOR_EFFECTORLIST] = GroupList
                      
                      c4d.EventAdd()
                  

                  Seems to work just fine up until adding the selection to the InExcludeData

                  <c4d.BaseObject object called Group/Group with ID 1019351 at 1949340925248>
                  [<c4d.BaseObject object called Plain.2/Plain with ID 1021337 at 1949342765760>, <c4d.BaseObject object called Plain.3/Plain with ID 1021337 at 1949342765632>, <c4d.BaseObject object called Plain.4/Plain with ID 1021337 at 1949342766400>]
                  Traceback (most recent call last):
                    File "Python", line 10, in main
                  TypeError: argument 1 must be c4d.BaseList2D, not list
                  

                  I'm getting this error at the bottom with the objects being a "list" instead of "c4d.BaseList2D". Can't seem to figure this one out.

                  I'm really confused on why "GetChildren" doesn't work while GetNext and GetDown seem to work just fine. GetChildren seems like it's the ideal way to do this since I only want the children and none of the grand children.

                  i_mazlovI 1 Reply Last reply Reply Quote 0
                  • H hoffwerr deleted this topic on
                  • i_mazlovI i_mazlov restored this topic on
                  • i_mazlovI
                    i_mazlov @hoffwerr
                    last edited by

                    Hi @hoffwerr ,

                    Please check our Support Procedures about consolidating consequent answers in a single posting. Please also do not duplicate your threads!

                    I assume this question was answered in your second thread: GetChildren into an InExcludeData.

                    Cheers,
                    Ilia

                    MAXON SDK Specialist
                    developers.maxon.net

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