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

    Merge IsolateObjects into a second document

    Cinema 4D SDK
    r20 python windows
    2
    2
    499
    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.
    • O
      owen
      last edited by

      I have a list of objects in one document (OptimizedDoc) that I want to copy over into another (doc) with materials and tags. My current code is:

      tempDoc = c4d.documents.IsolateObjects(OptimizedDoc, Transfer_Objects)
      c4d.documents.MergeDocument(doc, tempDoc, c4d.SCENEFILTER_NONE)
      

      I get - TypeError: unable to convert c4d.documents.BaseDocument to @net.maxon.interface.url-C
      The documentation says the second spot on Merge Document should be the file to merge into doc, but I think the way I'm presenting it is incorrect. Am I supposed to be pointing to a file location in memory? Thanks!

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

        hi,

        you have to save the document to memory and use the result to merge the document.
        When you merge, you have to set the flags to what you want to merge, otherwise it will not merge what you want.

        On this example i'm merging a document with another selected document.

        import c4d
        from c4d import gui
        # Welcome to the world of Python
        
        
        # Main function
        def main():
            
            obj = doc.GetActiveObject()
            if obj is None:
                return
            # Isolate the active object
            isolateDoc = c4d.documents.IsolateObjects(doc, [obj])
            
            # Creates the Memory File Strcuture
            mfs = c4d.storage.MemoryFileStruct()
            
            # Sets the mfs to write mode
            mfs.SetMemoryWriteMode()
            # save the document to mfs
            c4d.documents.SaveDocument(isolateDoc, mfs, c4d.SAVEDOCUMENTFLAGS_DONTADDTORECENTLIST, c4d.FORMAT_C4DEXPORT)
            # retrieve the data    
            data = mfs.GetData()
            # Set the MFS to read mode
            mfs.SetMemoryReadMode(data[0], data[1] )    
            
            
            flags =  c4d.SCENEFILTER_OBJECTS | c4d.SCENEFILTER_MATERIALS
            
            # Load Document 
            selectedFile = c4d.storage.LoadDialog()
            if selectedFile is None:
                return
            newDoc = c4d.documents.LoadDocument(selectedFile, flags)
            
            
            #Merge the isolated document with the current one.
            
            c4d.documents.MergeDocument(newDoc, mfs, flags)
            
            c4d.documents.InsertBaseDocument(newDoc)
            c4d.documents.SetActiveDocument(newDoc)
            
        
        # Execute main()
        if __name__=='__main__':
            main()
        

        Cheers,
        Manuel

        MAXON SDK Specialist

        MAXON Registered Developer

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