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

    Is it possible to intercept rendering to modify the document that is about to render?

    Cinema 4D SDK
    python s26 windows sdk
    3
    4
    590
    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
      HerrMay
      last edited by

      Hi guys,

      while I know how to retrieve information about when a render notification is invoked - thanks to @m_adam who provided an example in this thread - I wonder if it is possible to intercept the render pipline to modify the document that is about to render.

      The basic idea here would be something like this:

      • Receive the message when rendering starts
      • Run e.g. "Make Editable" on e.g. Subdivision Surfaces BUT for the render document only. I dont't want the SDS to be made editable in the working document.

      I know that c4d clones the document for rendering. Maybe there is a way to get hold of that document and run aforementioned command?

      Cheers,
      Sebastian

      ferdinandF 1 Reply Last reply Reply Quote 0
      • ferdinandF
        ferdinand @HerrMay
        last edited by ferdinand

        Hello @HerrMay,

        Thank you for reaching out to us.

        Is it possible to intercept rendering to modify the document that is about to render?

        All in all, yes, it is possible, but it is not recommended. MSG_MULTI_RENDERNOTIFICATION is accompanied by the render document in its message data. But modifying the render document is something one does at one's own risk at the moment. For public users, this document is meant to be read only.

        With that being said, nothing prevents you from modifying the document. But when the rendering is an editor rendering, the passed document will be the active document, i.e., you will change the active document. Click the video link below to see what I mean.

        In Python this is even more problematic, as one cannot distinguish between renderings which clone the document and one's which do not.

        Cheers,
        Ferdiand

        Code:

        """Demonstrates a Python Programming tag which inserts sphere objects into the documents of upcoming
        renderings.
        
        WHAT IS SHOWN HERE IS NOT AN INTENDED USE OF MSG_MULTI_RENDERNOTIFICATION. The passed document is meant
        to be treated as read only for public API users. Modify at your own risk.
        """
        import c4d
        
        doc: c4d.documents.BaseDocument # The document evaluating this tag
        
        def main() -> None: pass
        
        def message(mid: int, data: object) -> bool:
            """Called by Cinema 4D to convey messages to the tag.
            """
            # There is an upcoming rendering.
            if mid == c4d.MSG_MULTI_RENDERNOTIFICATION and data["start"]:
                # Get the render document.
                doc: c4d.documents.BaseDocument = data["doc"]
        
                # Insert a sphere.
                sphere: c4d.BaseObject = c4d.BaseObject(c4d.Osphere)
                if not sphere:
                    raise MemoryError()
        
                doc.InsertObject(sphere)
                
            return True
        

        MAXON SDK Specialist
        developers.maxon.net

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

          Hi @ferdinand,

          hmm... interesting. So while this is not the intentional way of using MSG_MULTI_RENDERNOTIFICATION it is good to know that it IS possible to act on the document used for rendering.

          I wonder if one could additionally check for data["external"] to modify the render document only? At least in the code example below it works to make the sphere editable and use that one for rendering.

          Cheers,
          Sebastian

          """Demonstrates a Python Programming tag which inserts sphere objects into the documents of upcoming
          renderings.
          
          WHAT IS SHOWN IS NOT AN INTENDED USE OF MSG_MULTI_RENDERNOTIFICATION. The passed document is meant
          to be treated as read only for public API users. Modify at your own risk.
          """
          import c4d
          
          doc: c4d.documents.BaseDocument # The document evaluating this tag
          
          def make_editable(doc, node):
          
              settings = c4d.BaseContainer()
          
              res = c4d.utils.SendModelingCommand(
                  command=c4d.MCOMMAND_MAKEEDITABLE,
                  list=[node],
                  mode=c4d.MODELINGCOMMANDMODE_ALL,
                  bc=settings,
                  doc=doc
              )
          
              if not res:
                  return
          
              obj = res[0]
              return obj.GetClone()
          
          def main() -> None:
              pass
          
          def message(mid: int, data: object) -> bool:
              """Called by Cinema 4D to convey messages to the tag.
              """
              # There is an upcoming rendering.
              if mid == c4d.MSG_MULTI_RENDERNOTIFICATION and data["start"] and data["external"]:
                  # Get the render document.
                  doc: c4d.documents.BaseDocument = data["doc"]
          
                  # Insert a sphere.
                  sphere: c4d.BaseObject = c4d.BaseObject(c4d.Osphere)
                  if not sphere:
                      raise MemoryError()
          
                  obj = make_editable(doc, sphere)
                  doc.InsertObject(obj)
          
              return True
          
          1 Reply Last reply Reply Quote 0
          • M
            m_adam
            last edited by

            Hello @HerrMay,

            without further questions or postings, we will consider this topic as solved by Monday 05/06/2023 and flag it accordingly.

            Thank you for your understanding,
            Maxime.

            MAXON SDK Specialist

            Development Blog, MAXON Registered Developer

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