Solved Dialog refresh works correct in R18... not in R21 ?

LogoButton.SetImage... (image of gui changes)
More code....
LogoButton.SetImage again. (image of gui changes)
End of code.

Problem in R21:
In R18 the image changes, then the rest of code keeps runing.
In R21 nothing is updated until the end of the code.

So in R18 this works correctly, but in R21 the bitmap of the button in the dialog Never changes until all the operations ends.

The only way I found to see the gui update in R21 is:
(of course just as test to help me detect the problem):Calling the command to show the About screen of C4D or opening a Modal dialog so the bitmap changes, then when the modal dialog is closed the operation goes on.... I tried this that already works in R18:

All this doesn't seems to force the update of dialog on R21, it will only update the image on the end of the operations or until a modal dialog or about screen of c4d appears...


First, for your next threads, please help us keeping things organised and clean. I know it's not your priority but it really simplify our work here.

I've added the tags and marked this thread as a question so when you considered it as solved, please change the state :)

About your issue, there's too much dark spot.

You are setting image of a imageButton but we need to know on witch function you are doing it.
c4d.EventAdd() push a update event in the stack and DrawViews refresh cinema4D view (with also updating the scene)
It's probably too much updates, just because you change the image of a button.

So, are you doing that on your Command function ? CreateLayout ? Message ?

Can you share a bit of your code ?


MAXON SDK Specialist

MAXON Registered Developer

Thank you for answering!
Here a gif showing the problem, left side R18, right side R21
Main difference:
It seems R21 is not even updating the console for each print, it just updates when script ends
R21 Dialog Update Problem.gif

1 - self.btnImage.SetImage(self.image2, True) #Change image first
2 - self.testCode() # Sample test code just prints lot of stuff in console...
3 - self.btnImage.SetImage(self.image1, True) #Change image again


Thanks for taking the time of doing that Gif, but i think i already understood what was your issue. Now we need to find the cause.
I've asked you questions to be able to point you to the right direction or investigate the issue.

Are you doing that on your Command function ? CreateLayout ? Message ?
As it seems to just be a dialogbox with a button, maybe you can share your code and we can directly test it.

With what you gave us, we can simply "guess" what you are doing.


MAXON SDK Specialist

MAXON Registered Developer

Here a link:
Download Code Here

Maybe is the same problem/solution:
Is there a way to make the console behaves like in R18 that updates each time a print is done and it doesn't wait the full script to end to show the prints? for example a a simple for loop that prints stuff

Thank you

Your link has expired. You can post the code directly in a posting, just use the little brackets icon.


MAXON SDK Specialist

I ziped because it contains 2 images in the folder 'res' of the plugin location:
*I think that just finding a way to update the interface like when the console prints each print in a While loop like it behaves in R18 it can be the same solution for this problem

import c4d, os
from c4d import gui, documents
from c4d import utils
from c4d import plugins


#Welcome to the world of Python
class MiDialogo(c4d.gui.GeDialog):
    dir, file = os.path.split(__file__)  # Gets the plugin's directory
    images_Path = os.path.join(dir, 'res')  # Adds the res folder to the path
    image1 = os.path.join(images_Path, 'image1.jpg')
    image2 = os.path.join(images_Path, 'image2.jpg')

    def CreateLayout(self):
        bc = c4d.BaseContainer()  # Create a new container to store the button image
        bc.SetBool(c4d.BITMAPBUTTON_BUTTON, True)
        self.AddStaticText(241798101, c4d.BFH_CENTER, 0, 0, name='Change bitmap first, run more code, then change again')
        self.btnImage = self.AddCustomGui(241798100, c4d.CUSTOMGUI_BITMAPBUTTON, "Bitmap Button", c4d.BFH_CENTER, 60, 70, bc)
        self.AddButton(241798102, c4d.BFH_CENTER, initw=150, inith=20, name="Test")
        self.btnImage.SetImage(self.image1, True)
        return True

    def testCode(self):
        i = 1
        while i < 6000:
            i += 1

    def Command(self, id, msg):
        if id == 241798102:
            #Change bitmap first, then run code, then change bitmap again
            self.btnImage.SetImage(self.image2, True) #Change image first
            self.testCode() # Sample test code
            #gui.MessageDialog('Here a code instead of a popup', c4d.GEMB_OK)
            self.btnImage.SetImage(self.image1, True) #Change image again

        return True

class MyMenuPlugin(c4d.plugins.CommandData):
    dialog = None
    def Execute(self, doc):
    # create the dialog
       if self.dialog is None:
          self.dialog = MiDialogo()
       return self.dialog.Open(dlgtype=c4d.DLG_TYPE_ASYNC, pluginid=PLUGIN_ID, defaultw=200, defaulth=150, xpos=-1, ypos=-1)

    def RestoreLayout(self, sec_ref):
    # manage the dialog
        if self.dialog is None:
            self.dialog = MiDialogo()
        return self.dialog.Restore(pluginid=PLUGIN_ID, secret=sec_ref)
if __name__=='__main__':
    okyn = plugins.RegisterCommandPlugin(PLUGIN_ID, "Change bitmap test",0,None, "Change bitmap test", MyMenuPlugin())
    if (okyn):
        print "Change bitmap test"

No solution? mm No way to force update of the dialog/console during the script as R18 behaves? to see each print at the right moment instead of waiting untild end of script or a modal dialog to appear to update dialog/console?
R21 Dialog Update Problem.gif


i can confirm the issue here even in c++.

There are two issue here.
The python console have been changed a lot. Printing out things in the console is really slow. (in general)
With the last versions, you can print out lots of data and it doesn't block your code. That's why your loop execute really faster in R20/21 than on previous version.
There's no "flag" to make the console act as before.

The BitmapButton not updating is a lot more important and look like a bug.

This is under investigation and I'll be back to confirm if it's a bug. (both issue)


MAXON SDK Specialist

MAXON Registered Developer

@m_magalhaes Thank you a lot!


I don't think the console will be changed and with the R21, the redraw have been modified a bit.
Your code block the execution of the command and should not. This could be done differently but would lead to a bit more work.

The easiest way to "force" the update of the dialog box is to ask for the mouse state. This will force the os to ask for a redraw and c4d will redraw the box.

Just add :

            self.SetString(1003, "Before")
            self.btnImage.SetImage(self.image2, True) #Change image first          
            bc = c4d.BaseContainer()
            c4d.gui.GetInputState(c4d.BFM_INPUT_MOUSE, c4d.BFM_INPUT_CHANNEL, bc)


MAXON SDK Specialist

MAXON Registered Developer

@m_magalhaes Epic, It works! :) Thank you very much Manuel!