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

    Finding name/handle to last object merged into scene

    Cinema 4D SDK
    3
    3
    569
    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.
    • N
      nicholas_yue
      last edited by nicholas_yue

      After calling MergeDocument()

      merge_status = c4d.documents.MergeDocument(doc, path,
                                                 c4d.SCENEFILTER_MERGESCENE | c4d.SCENEFILTER_OBJECTS)
      

      I check merge_status to be true and wish to find some handle/name to the object associated with the call to MergeDocument(), how do I do that ?

      I tried the following on an empty scene

              doc = c4d.documents.GetActiveDocument()
              ao = doc.GetActiveObject()
      

      that works if I am calling MergeDocument for a single path but if I am calling MergeDocument (in a loop) for a collection of paths, GetActiveObject() points to the same object, not the next one corresponding to the next path I am merging into the scene

      Cheers

      1 Reply Last reply Reply Quote 0
      • ManuelM
        Manuel
        last edited by

        Hi,

        there's no direct way of doing it. You must store the different object. Either you can store the original object's list and select/inverse the selection to retrieve all the objects that were not in the original document. Or you can store the object in a list each time you import a document.

        import c4d
        import os
        from c4d import gui
        
        
        def GetNextObject(op):
            if op==None:
                return None
          
            if op.GetDown():
                return op.GetDown()
          
            while not op.GetNext() and op.GetUp():
                op = op.GetUp()
          
            return op.GetNext()
         
        
        def GetOriginalObjectList():
            originalObjects = list()
            child = doc.GetFirstObject()
            if child is None:
                return originalObjects
            
            while child:
                originalObjects.append(child)
                child = GetNextObject(child)
            
            return originalObjects
        
        
        
        
        def main():
            # Store the original object in a list
            originalObjects = GetOriginalObjectList()
            mergedObject = list()
            
            path="D:\\MAXON\\temp\\merging_doc"
            for root, dirs, files in os.walk(path):
                for name in files:
                    filePath = os.path.join(path,name)
                    merge_status = c4d.documents.MergeDocument(doc, filePath, c4d.SCENEFILTER_MERGESCENE | c4d.SCENEFILTER_OBJECTS)
                    if merge_status:
                        mergedObject.append(doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_CHILDREN))
        
            c4d.CallCommand(100004767) # Deselect All object
            # select all object that were on the orignal document
            for obj in originalObjects:
                obj.SetBit(c4d.BIT_ACTIVE)
            
            c4d.CallCommand(100004794) # Invert Selection    
        
            #Print all the object list we gather during the import.
            for objList in  mergedObject:
                print (objList)
                  
            c4d.EventAdd()
        
        # Execute main()
        if __name__=='__main__':
            main()
        

        Cheers,
        Manuel

        MAXON SDK Specialist

        MAXON Registered Developer

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

          Hello @nicholas_yue,

          without any further questions or postings, we will consider this topic as solved by Wednesday and flag it accordingly.

          Cheers,
          Ferdinand

          MAXON SDK Specialist
          developers.maxon.net

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