SOLVED SetActiveRenderData Does Not Work As Expected?

Hi,

I have a code that

  1. saves the current render data setting
  2. modifies render data
  3. restores #1 render data

The problem is in #3. Render data is not restored. It stays as in #2

You can check the code here:

import c4d

# Main function
def main():
    
    doc = c4d.documents.GetActiveDocument()
    rd_saved = doc.GetActiveRenderData()
    
    rd = doc.GetActiveRenderData()

    rd[c4d.RDATA_RENDERENGINE]  = c4d.RDATA_RENDERENGINE_PREVIEWHARDWARE
    rd[c4d.RDATA_XRES] = 200
    rd[c4d.RDATA_YRES] = 200
    rd[c4d.VP_PREVIEWHARDWARE_ANTIALIASING] = 3
        

    doc.SetActiveRenderData(rd_saved)


# Execute main()
if __name__=='__main__':
    main()

Is there a way around this?

Thank you

RenderData objects are objects stored with the BaseDocument, representing a set of render settings.

GetActiveRenderData() returns a reference to such an object. So calling GetActiveRenderData() twice just returns two references to the same object.

If you want to store the previous state, you could simply get a clone:

rd_saved = doc.GetActiveRenderData().GetClone()

and use that clone to restore the original state:

rd_saved.CopyTo(rd, c4d.COPYFLAGS_NONE)

But without knowing what you actually want to achive, it is hard to say if that is a good solution or not.

Also, assuming this is a Script Manager script: doc = c4d.documents.GetActiveDocument() is useless.

@PluginStudent

Thanks for the explanation.
Your solution works as expected 🙂