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

    Retrieve Merged Objects

    PYTHON Development
    0
    3
    562
    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
      Helper
      last edited by

      On 09/07/2018 at 21:09, xxxxxxxx wrote:

      I'm trying to merge a directory full of .obj files into my scene, but after each merged .obj I need to perform some operations on the newly added objects before merging the remaining files.

      Here's the function I'm using to merge the .obj for now:

      def mergeObj(path) :
          obj_loader = plugins.FindPlugin(c4d.FORMAT_OBJ2IMPORT, c4d.PLUGINTYPE_SCENELOADER)
        
          if obj_loader:
              data = {}
              obj_loader.Message(c4d.MSG_RETRIEVEPRIVATEDATA, data)
              bc = data['imexporter'].GetDataInstance()
              bc.SetInt32(c4d.OBJIMPORTOPTIONS_SPLITBY, 3)
              return documents.MergeDocument(doc, path, loadflags = c4d.SCENEFILTER_NOUNDO | c4d.SCENEFILTER_OBJECTS | c4d.SCENEFILTER_MATERIALS | c4d.SCENEFILTER_MERGESCENE)
        
          return False
      

      This function currently returns True or False but I'd rather that it return the highest level object inserted by the MergeDocument() call. What's the best way to do that?

      I foolishly thought that I might be able to return doc.GetActiveObject() to get the top level BaseObject because that works after using the 'Merge...' menu item, but calling MergeDocument() doesn't seem to change the active object.

      Thanks for any help!

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

        On 09/07/2018 at 22:06, xxxxxxxx wrote:

        I came up with a solution.

        Store doc.GetObjects() before the merge operation, then build a list from doc.GetObjects() after the merge but exclude anything in the previous list.

        Not as clean as I'd like but it seems to work well.

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

          On 10/07/2018 at 01:36, xxxxxxxx wrote:

          Hi Darby,

          Your way is correct, another way could be to import all the objects in a temporary document, list the objects in this temporary documents, and then merge this document with the final one.

          If you have any question, please let me know.
          Cheers,
          Maxime

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