SetActiveRenderData Does Not Work As Expected?
-
Hi,
I have a code that
- saves the current render data setting
- modifies render data
- 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 theBaseDocument
, representing a set of render settings.GetActiveRenderData()
returns a reference to such an object. So callingGetActiveRenderData()
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. -
Thanks for the explanation.
Your solution works as expected