Hi,
I wanted to register the "Enter" Key as if I clicked a button.
It works on a singular script, but when I implement it to my code base it errors as
RuntimeError: maximum recursion depth exceeded
If I just click the button where it goes through Command
, it executes only once.
If I hit enter where it goes through Message
, it executes for more than 200+ times, which I believe what causes the maximum recusion.
Is there a way to limit the execution to only 1? (i.e. when I just hit "Enter")
You can see the singular script code here. Execute it and you'll see more than 200+ entries in the console.
import c4d
rename_pose_rename_string = 101010
rename_pose_btn = 202020
class rename_dialog(c4d.gui.GeDialog):
def __init__(self):
self.rename_string = ''
def CreateLayout(self):
self.SetTitle('Rename')
self.AddEditText(id=rename_pose_rename_string, flags=c4d.BFH_CENTER, initw=400, inith=0, editflags=0)
self.AddButton(id=rename_pose_btn, flags=c4d.BFH_CENTER, initw=50, inith=0, name="Rename")
return True
def Command(self, id, msg):
if id == rename_pose_btn:
self.rename_string = self.GetString(id=rename_pose_rename_string)
print "Button Clicked"
self.Close()
return True
def Message(self, msg, result):
bc = c4d.BaseContainer()
ok = c4d.gui.GetInputState(c4d.BFM_INPUT_KEYBOARD,c4d.KEY_ENTER, bc)
if ok:
if bc[c4d.BFM_INPUT_VALUE] == 1:
print "Enter"
self.rename_string = self.GetString(id=rename_pose_rename_string)
self.Close()
return c4d.gui.GeDialog.Message(self, msg, result)
dlg = rename_dialog()
dlg.Open(dlgtype=c4d.DLG_TYPE_MODAL)
rename_string = dlg.rename_string