Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python 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

    Take Viewport Screenshot

    Cinema 4D SDK
    r21 python
    5
    6
    1.8k
    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.
    • B
      bentraje
      last edited by

      Hi,

      Is there a way to take a viewport screenshot (i.e. exactly what the viewport is displayed)?
      I have a WIP code but it uses a camera independent of the current camera the viewport is looking at:

      You can also check the illustration of the problem here:
      https://www.dropbox.com/s/qtzemdng92w13od/c4d190_take_viewport_picture.mp4?dl=0

      def main():
          bmp = doc.GetDocPreviewBitmap()
          c4d.bitmaps.ShowBitmap(bmp)
          c4d.EventAdd()
      

      Thank you for looking at my problem

      1 Reply Last reply Reply Quote 0
      • S
        s_bach
        last edited by

        Hello,

        just FYI: GetDocPreviewBitmap() returns the image that is stored in the c4d file and that is used as a thumbnail image. It is created when the scene is saved; it has nothing to do with the current viewport image.

        MAXON SDK Specialist

        Development Blog, MAXON Registered Developer

        1 Reply Last reply Reply Quote 1
        • mikeudinM
          mikeudin
          last edited by mikeudin

          You have to make render with Software Renderer.

          Checkout my python tutorials, plugins, scripts, xpresso presets and more
          https://mikeudin.net

          1 Reply Last reply Reply Quote 1
          • a_blockA
            a_block
            last edited by a_block

            There's also the "Send to Picture Viewer" command (by default in viewport View menu), command ID is 300001097, which would fit your purpose quite well...
            Unfortunately it has some downsides, when trying to use it from code instead of from the UI.

            • With multiple viewports you lack an option to choose the viewport, instead the active one will be taken.
            • With multiple viewports there's a bug, which sometimes leads to a black image.

            Cheers

            Edit: Forget it, playing around with it, I think it is broken for every other than the first viewport (regardless of code or UI). Sorry.

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

              hello,

              as @mikeudin said you have to render the document using Software renderer.
              Change the render setting to software/hardware renderer, use RenderDocument and retrieve the result.
              After that, change back the render engine to what it was.

              import c4d
              from c4d import gui
              
              
              # Main function
              def main():
                   # Retrieves the current active render settings
                  rd = doc.GetActiveRenderData()
                  saved = rd[c4d.RDATA_RENDERENGINE] 
                  rd[c4d.RDATA_RENDERENGINE]  = c4d.RDATA_RENDERENGINE_PREVIEWHARDWARE
                  
                  # Creates a Multi Pass Bitmaps that will store the render result
                  bmp = c4d.bitmaps.MultipassBitmap(int(rd[c4d.RDATA_XRES]), int(rd[c4d.RDATA_YRES]), c4d.COLORMODE_RGB)
                  if bmp is None:
                      raise RuntimeError("Failed to create the bitmap.")
              
                  # Adds an alpha channel
                  bmp.AddChannel(True, True)
              
                  # Renders the document
                  if c4d.documents.RenderDocument(doc, rd.GetData(), bmp, c4d.RENDERFLAGS_EXTERNAL) != c4d.RENDERRESULT_OK:
                      raise RuntimeError("Failed to render the temporary document.")
              
                  # Displays the render in the Picture Viewer
                  c4d.bitmaps.ShowBitmap(bmp)
              
                  rd[c4d.RDATA_RENDERENGINE] = saved
              
              if __name__ == "__main__":
                  main()
              
              
              

              Cheers,
              Manuel

              MAXON SDK Specialist

              MAXON Registered Developer

              1 Reply Last reply Reply Quote 2
              • B
                bentraje
                last edited by

                Thank you all for the response. Appreciate a lot.

                Specially for the sample code provided by @m_magalhaes as this is my code relating to rendering.

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