Solved How to work with LoadFile from content browser

My goal is to quickly replace high poly models with low poly versions. The high poly models are being pulled from a library by architects, so the names are complex and always the same. I have started building a document in Cinema with low poly versions of these with correct UV and textures that I saved to the content browser. My thinking is that when I import their model, I run a script that
1 - Creates a list of all the active objects in the current scene
2 - Opens the document that holds the low poly versions
3 - Copy any objects in the low poly document that match the list of objects from the architect's model
4 - Paste those objects in to the document that has the architect's model
5 - Replace the high poly models with the low poly version

The part I'm stuck on is opening and then working with the document from the content library. This is my code so far:

def main():

    #Make list of selection
    Object_List = doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_CHILDREN)

    #Open low poly library file from content browser

    #This is where I would compare the objects in the scene to the Object_List
    print c4d.documents.BaseDocument.GetObjects(doc)

The console prints out a list of objects in the architects model, so I'm wondering why that stays as doc and not the file that was just loaded and how to switch between the files I want to work with in python?

doc never changes in your code. The predefined variable doc refers to the active document at the beginning of the script, which I assume is the architect's model. Opening a new scene through LoadFile does not change doc so you are still getting the object list for your original document. Try using lowResDoc = c4d.documents.GetActiveDocument() to get the newly opened document.

@Cairyn Perfect, that did the trick, thanks!


you could also use LoadDocument

lowPoly = c4d.documents.LoadDocument("preset://Optimized_Assets.lib4d/Asset_Library.c4d", c4d.SCENEFILTER_OBJECTS | c4d.SCENEFILTER_MATERIALS)

As the documentation says:
Similar to LoadFile() but this time the document is not put into the editors list of documents and it gives control over the loaded document.


MAXON SDK Specialist

MAXON Registered Developer