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

    Set Document Preview

    PYTHON Development
    0
    9
    1.1k
    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 24/01/2014 at 10:28, xxxxxxxx wrote:

      Is there a way to set the document preview or force it to create one when saving a file via the SaveProject() function?

      None of the files generated by my script have a preview of the scene when selected in the browser of Mac OS X.  Documents I manually save show a preview when selected in the file browser.

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

        On 26/01/2014 at 04:02, xxxxxxxx wrote:

        Hi,

        check out the following piece of code. This might help you how to initialize and set the preview bitmap.

        import c4d
        import os
          
        def SetDocumentPreviewBitmap(doc, fn) :
            previewBmp = doc.GetDocPreviewBitmap()
            if not os.path.exists(fn) :
                raise StandardError, "Bitmap file does not exist"
            
            if not previewBmp.InitWith(fn) :
                raise StandardError, "Could not load file"
          
            return
          
        d = c4d.documents.BaseDocument()
        d.InsertObject(c4d.BaseObject(c4d.Ocube)) #there must be at least one object in the scene to generate a preview
          
        SetDocumentPreviewBitmap(d, "C:\\Users\\YourUserName\\Desktop\\abc.png")
          
        c4d.documents.SaveDocument(d, "C:\\Users\\YourUserName\\Desktop\\file.c4d", c4d.SAVEDOCUMENTFLAGS_0, c4d.FORMAT_C4DEXPORT)
        

        Cheers

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

          On 28/01/2014 at 19:22, xxxxxxxx wrote:

          A belated thank you for the post. I was unable to get on the forum for some reason.  I've been busy with other stuff this week but hope to take a stab at it tomorrow.

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

            On 04/02/2014 at 08:14, xxxxxxxx wrote:

            I was able to take what you provided and get it working with a file saved to the hard drive and read back in to create the document preview.  Thank you for the direction.

            I would prefer to skip the saving file part.  The documentation for BaseBitmap.InitWith shows that it can be passed a string or a MemoryFileStruct.  I found the example script for writing a bmp to a MFS so I incorporated that into the script but must be missing something.  Im not getting any error messages but I'm not getting a preview either.

            I tried sending the bmp to the picture viewer and have confirmed everything is working from the render standpoint.  Any insight is appreciated.

            import c4d
            import os
            from c4d import bitmaps, documents, storage
              
            def WriteBitmap(bmp, format=c4d.FILTER_JPG,settings=c4d.BaseContainer()) :
                mfs = storage.MemoryFileStruct()
                mfs.SetMemoryWriteMode()
                hf = storage.HyperFile()
                if hf.Open(0, mfs, c4d.FILEOPEN_WRITE, c4d.FILEDIALOG_NONE) :
                    if not hf.WriteImage(bmp,format,settings) :
                        print "fail"
                        return None
                    hf.Close()
                return mfs
              
            d = c4d.documents.BaseDocument()
            d.InsertObject(c4d.BaseObject(c4d.Ocube)) 
            rd = d.GetActiveRenderData().GetData()
            xres = int(rd[c4d.RDATA_XRES])
            yres = int(rd[c4d.RDATA_YRES])
            bmp = bitmaps.BaseBitmap()
            bmp.Init(x=xres, y=yres, depth=24)
              
            rd[c4d.RDATA_RENDERENGINE] = c4d.RDATA_RENDERENGINE_PREVIEWHARDWARE 
            res = documents.RenderDocument(d, rd, bmp, c4d.RENDERFLAGS_EXTERNAL)
              
            mfs = WriteBitmap(bmp)
              
            if res==c4d.RENDERRESULT_OK:
                previewBmp = d.GetDocPreviewBitmap()
                if not previewBmp.InitWith(mfs) :
                    raise StandardError, "Not working"
              
            c4d.documents.SaveDocument(d, "filepath/file.c4d", c4d.SAVEDOCUMENTFLAGS_0, c4d.FORMAT_C4DEXPORT)
            
            1 Reply Last reply Reply Quote 0
            • H
              Helper
              last edited by

              On 04/02/2014 at 13:24, xxxxxxxx wrote:

              Hi,

              try use 'doc' for the current document and try again. Here it works fine then.

              Cheers,
              s_rath

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

                On 05/02/2014 at 06:19, xxxxxxxx wrote:

                Strange.  I changed it to previewBmp = doc.GetDocPreviewBitmap() and it still doesn't do it.  I end up with the generic c4d preview icon.

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

                  On 05/02/2014 at 06:35, xxxxxxxx wrote:

                  If I load an external file the result of bitmap.InitWith()  is (1, False)  when I run my MemoryFileStructure version the result is (-1, False).

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

                    On 18/02/2014 at 12:35, xxxxxxxx wrote:

                    Is it possible there is a difference between Mac and Windows implementation and we're on different platforms getting different results?  I'm doing this in OSX.

                    thanks again for your help.

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

                      On 20/02/2014 at 14:21, xxxxxxxx wrote:

                      No, the code here should work on Win and OSX the smae way.

                      Cheers, s_rath

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