Dear community,
I'm trying to scale a cube with a Slider in realtime. But I don't get it.
The cube is only scaled after the mouse is released and not in realtime.
import c4d
class SliderDialog(c4d.gui.GeDialog):
def __init__(self):
super().__init__()
self.slider_id = 1001
self.last_value = None
def CreateLayout(self):
self.SetTitle("Slider")
self.AddEditSlider(self.slider_id, c4d.BFH_SCALEFIT, initw=200)
self.SetFloat(self.slider_id, 0.0, min=0.0, max=1.0, step=0.01)
return True
def Command(self, id, msg):
if id == self.slider_id:
value = self.GetFloat(self.slider_id)
print(f"Real-time slider value: {value}")
self.UpdateScene(value)
return True
def Message(self, msg, result):
if msg.GetId() == c4d.BFM_ACTION_INDRAG:
value = self.GetFloat(self.slider_id)
if value != self.last_value:
self.last_value = value
print(f"Dragging slider value: {value}")
self.UpdateScene(value)
return super().Message(msg, result)
def UpdateScene(self, value):
doc = c4d.documents.GetActiveDocument()
obj = doc.SearchObject("Cube")
if obj:
obj[c4d.ID_BASEOBJECT_REL_SCALE, c4d.VECTOR_X] = value
c4d.EventAdd()
if __name__ == "__main__":
doc = c4d.documents.GetActiveDocument()
obj = doc.SearchObject("Cube")
if not obj:
obj = c4d.BaseObject(c4d.Ocube)
doc.InsertObject(obj)
c4d.EventAdd()
dlg = SliderDialog()
dlg.Open(c4d.DLG_TYPE_ASYNC)
Thank you in advance for your assistance.