Hi,
I'm using the illustration code in this thread.
It works.
But the problem is that it freezes viewport interaction. I can't cancel the progress bar midway the process. It has to be completed.
Is there a way around this?
import c4d
from c4d import gui
import time
class TestDialog(gui.GeDialog):
PROGRESSBAR = 1001
ID_BTN_01 = 1002
ID_BTN_02 = 1003
def __init__(self):
self.progress = 0
self.prim_list = [c4d.Ocube, c4d.Osphere, c4d.Ocylinder, c4d.Oplane, c4d.Otorus, c4d.Opyramid]
self.prim_length = len(self.prim_list)
def StopProgress(self):
self.progress = 0
progressMsg = c4d.BaseContainer(c4d.BFM_SETSTATUSBAR)
progressMsg.SetBool(c4d.BFM_STATUSBAR_PROGRESSON, False)
self.SendMessage(self.PROGRESSBAR, progressMsg)
def CreateLayout(self):
self.SetTitle("ProgressBar Example")
self.GroupBegin(id=1000, flags=c4d.BFH_SCALEFIT|c4d.BFV_TOP, cols=0, rows=1)
self.AddCustomGui(self.PROGRESSBAR, c4d.CUSTOMGUI_PROGRESSBAR, "", c4d.BFH_SCALEFIT|c4d.BFV_SCALEFIT, 0, 0)
self.GroupEnd()
self.GroupBegin(id = 1005, flags=c4d.BFH_SCALEFIT|c4d.BFV_TOP, cols=2, rows=1)
self.AddButton(self.ID_BTN_01, c4d.BFH_SCALEFIT, 100, 15, name="Create Primitives")
self.GroupEnd()
return True
def Command(self, id, msg):
if (id == self.ID_BTN_01):
#do something short
opecnt = self.prim_length;
for prim in self.prim_list:
obj = c4d.BaseObject(prim)
doc.InsertObject(obj)
c4d.EventAdd()
for x in range(opecnt):
self.progress += 1
progressMsg = c4d.BaseContainer(c4d.BFM_SETSTATUSBAR)
progressMsg[c4d.BFM_STATUSBAR_PROGRESSON] = True
progressMsg[c4d.BFM_STATUSBAR_PROGRESS] = self.progress/opecnt
self.SendMessage(self.PROGRESSBAR, progressMsg)
time.sleep(1)
self.StopProgress()
return True
def AskClose(self):
self.StopProgress()
return False
if __name__=='__main__':
dialog = TestDialog()
dialog.Open(dlgtype=c4d.DLG_TYPE_ASYNC, pluginid=0, defaulth=100, defaultw=400)