Retrieve Merged Objects
-
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!
-
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.
-
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