Is it possible to intercept rendering to modify the document that is about to render?
-
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 -
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.
-
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
-
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.