Refresh viewport after updating RenderData width and height
-
Hello,
I have a script that is used to update the resolution of the active document. Recently we implemented a way to get overscan size data (VFX work) and i'm having trouble with refreshing the viewport.
The issue resides in the fact that if you don't interact with the resolution slider or input something manually, the viewport show effectively the change with the Safe Frames but if there is an existing Background object/ Material with Frontal projection it will not update. Only an user interaction can help.Here are some code snippets that i used to showcase the issue and what i tried in terms of flags/update/dirty states :
import c4d import random def main(): doc = c4d.documents.GetActiveDocument() rd = doc.GetActiveRenderData() bd = doc.GetActiveBaseDraw() print(f"Render Data X_Res before : {rd[c4d.RDATA_XRES]}") print(f"Render Data Y_Res before : {rd[c4d.RDATA_YRES]}") print("-------------------------------------------------") xres = random.randint(0, 1920) yres = random.randint(0, 1080) rd[c4d.RDATA_XRES] = xres print(f"Render Data X_Res after : {rd[c4d.RDATA_XRES]}") rd[c4d.RDATA_YRES] = yres print(f"Render Data Y_Res after : {rd[c4d.RDATA_YRES]}") print("-------------------------------------------------") rd.Message(c4d.MSG_UPDATE) rd.SetDirty(c4d.DIRTYFLAGS_ALL) rd.SetDirty(c4d.DIRTYFLAGS_DATA) c4d.GeSyncMessage(c4d.EVMSG_UPDATEBASEDRAW) c4d.EventAdd() if __name__=='__main__': main()
import c4d import random def main(): doc = c4d.documents.GetActiveDocument() rd = doc.GetActiveRenderData() bd = doc.GetActiveBaseDraw() print(f"Render Data X_Res before: {rd[c4d.RDATA_XRES]}") print(f"Render Data Y_Res before: {rd[c4d.RDATA_YRES]}") print("-------------------------------------------------") xres = random.randint(1000, 1920) print(f"Random X_Res: {xres}") yres = random.randint(500, 1080) print(f"Random Y_Res: {yres}") # Set the new X and Y resolution using SetParameter rd.SetParameter(c4d.RDATA_XRES, xres, c4d.DESCFLAGS_SET_USERINTERACTION | c4d.DESCFLAGS_SET_FORCESET | c4d.DESCFLAGS_SET_INDRAG) rd.SetParameter(c4d.RDATA_YRES, yres, c4d.DESCFLAGS_SET_USERINTERACTION | c4d.DESCFLAGS_SET_FORCESET | c4d.DESCFLAGS_SET_INDRAG) print(f"Render Data X_Res after: {rd[c4d.RDATA_XRES]}") print(f"Render Data Y_Res after: {rd[c4d.RDATA_YRES]}") print("-------------------------------------------------") print("-------------------------------------------------") rd.Message(c4d.MSG_UPDATE) rd.SetDirty(c4d.DIRTYFLAGS_ALL) rd.SetDirty(c4d.DIRTYFLAGS_DATA) c4d.GeSyncMessage(c4d.EVMSG_UPDATEBASEDRAW) c4d.DrawViews(c4d.DRAWFLAGS_FORCEFULLREDRAW) c4d.EventAdd() if __name__=='__main__': main()
Video showcasing the issue :
-
Hello @shivamist,
Welcome to the Maxon developers forum and its community, it is great to have you with us!
Getting Started
Before creating your next postings, we would recommend making yourself accustomed with our forum and support procedures. You did not do anything wrong, we point all new users to these rules.
- Forum Overview: Provides a broad overview of the fundamental structure and rules of this forum, such as the purpose of the different sub-forums or the fact that we will ban users who engage in hate speech or harassment.
- Support Procedures: Provides a more in detail overview of how we provide technical support for APIs here. This topic will tell you how to ask good questions and limits of our technical support.
- Forum Features: Provides an overview of the technical features of this forum, such as Markdown markup or file uploads.
It is strongly recommended to read the first two topics carefully, especially the section Support Procedures: Asking Questions.
About your First Question
You did a great job in your first posting with providing all the information we need. But I still struggle a bit with understanding your core issue. Your claim is "The issue resides in the fact that if you don't interact with the resolution slider or input something manually, the viewport [do not] show [...] the change with the Safe Frames [...] if there is an existing Background object/ Material with Frontal projection [...]".
I cannot reproduce this, nor does your video show that IMHO. Could you please elaborate and/or give us a scene file?
Cheers,
FerdinandThis is what I did:
-
@ferdinand
Here is the User action that fixes the viewport aspect ratio :
-
What I more meant was: What would you consider incorrect in my video/when running your script? And while I write this I sort of have an epiphany So, you mean your script fails when you have a BG object and the user manually interacts with the Render settings to change a value and you then run your script?
Because in my video and also yours, things are updating just fine I would say?
-
@ferdinand
What's incorrect is the aspect ratio of the Background object or anything material that is in a Frontal projectionIn the following screenshot you can see that on the border of the Safe Frames (turned them red for easier readability), the Background object stops at the border of the image
Here is the result after using the script with SetParameter() :
I hope the issue is clear now, the expected behavior would be that if the resolution changes, the background object should follow
-
Yes, this clarifies things, thanks a lot. I will have a look (but only tomorrow since I am now already on my Linux machine).
Cheers,
Ferdinand -
Hey @shivamist,
After some poking in the code, I found out you were effectively writing to the wrong parameter, you should write to the virtual resolutions in this case, and also learnt something myself. Find my answer in detail below.
Cheers,
FerdinandResult
-
Hello @ferdinand ! Thanks for answer it is very clear, i will use virtual resolution from now on