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

    Insert under with itertools

    Scheduled Pinned Locked Moved PYTHON Development
    3 Posts 0 Posters 576 Views
    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 Offline
      Helper
      last edited by

      On 29/01/2018 at 14:09, xxxxxxxx wrote:

      Hi,
      python noob here.

      I have 2 lists with objects declared by their name as string. I align the matrix of the corresponding objects using itertools:
      for J,N in itertools.izip(list1,list2) :

      That works very well. But now I also want to insert the objects from list1 also under the objects from list2 in the OM as children. I get now the error "list object has no attribute insertUnder". Ok, is there a workaround how to do that?

      Thx

      1 Reply Last reply Reply Quote 0
      • H Offline
        Helper
        last edited by

        On 30/01/2018 at 02:14, xxxxxxxx wrote:

        Hi,

        welcome to the Plugin Café forums 🙂

        I'm not so sure about the first part of your description. In Cinema 4D Objects (BaseObject) are derived from (among other classes) GeListNode, which basically represents a node in the Object Manager tree. The functions to insert children are GeListNode.InsertUnder() (note the capital I) or InsertUnderLast().

        If this does not solve your issue, please provide us with more code, so we can get a better understanding of your situation.

        1 Reply Last reply Reply Quote 0
        • H Offline
          Helper
          last edited by

          On 14/02/2018 at 09:12, xxxxxxxx wrote:

          Hi,
          thanks for the answer. For an artist with very basic coding skills it is not so easy to even know what to look for in the SDK. That is the structre I prefer to use since I have an overview in the code about the 2 objects that go together:

          import c4d
          from c4d import gui
          import itertools

          Nulls = ["Null1",   "Null2" ,    "Null3"  ,  "Null4"]
          PositNull = ["N_Null1","N_Null2","N_Null3", "N_Null4"]

          def main() :
           
            for J,N in itertools.izip(Nulls,PositNull) :
               
                obj = doc.SearchObject(J)
                if obj is None: return False
                matrix = obj.GetMg()        #the global matrix
                globalPos = matrix.off      #get the position from the matrix
               
                obj2 = doc.SearchObject(N)
                if obj2 is None: return False
                matrix2 = obj2.GetMg()        #the global matrix
                globalPos2 = matrix2.off      #get the position from the matrix
               
                m = matrix2
                m.off = globalPos2     #get the position from the Object Matrix
                obj.SetMg(m)           #Sets the global matrix of 1 to 2
               
                c4d.EventAdd()

          if __name__=='__main__':
            main()

          Now I want to add the feature that the according objects align in OM hierarchy as well.

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