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

    How to work with LoadFile from content browser

    Cinema 4D SDK
    python windows r20
    3
    4
    653
    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

      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
          c4d.documents.LoadFile("preset://Optimized_Assets.lib4d/Asset_Library.c4d")
      
          #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?

      1 Reply Last reply Reply Quote 0
      • CairynC
        Cairyn
        last edited by

        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.

        O 1 Reply Last reply Reply Quote 1
        • O
          owen @Cairyn
          last edited by

          @Cairyn Perfect, that did the trick, thanks!

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

            hi,

            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.

            Cheers,
            Manuel

            MAXON SDK Specialist

            MAXON Registered Developer

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