Solved Cinema 4D R20 (20026) GeDialog.SetLong, SetInt32 OverflowError

Hello guys!
Working on updating plugins for C4D R20.
Have an error: "OverflowError: unsigned byte integer is greater than maximum" when trying to update Tool plugin interface EditNumberArrows field with numbers greater then 255 (there is no error if number less or equal then 255) using commang
GeDialog.SetInt32(0001,int(var),min=0, max=c4d.MAXLONGl, step=1, tristate=False, min2=0, max2=c4d.MAXLONGl)
or
GeDialog.SetLong(0001,int(var),min=0, max=c4d.MAXLONGl, step=1, tristate=False, min2=0, max2=c4d.MAXLONGl)

On C4D R19 it works fine...

Checkout my python tutorials, plugins, scripts, xpresso presets and more
https://mikeudin.net

Hi,

The OverFlow error is thrown when SetInt32() is called from a SubDialog (used for Tool plugins settings).
I'm afraid a regression was introduced in R20. It will be fixed in the next update.

The workaround in R20 is to perform in Python what GeDialog::SetInt32() does in the C++ API (see cinema.framework/source/c4d_gui.cpp).

import sys

def StringToID(str):
  return int('0x'+hex(ord(str[0]))[2:4]+hex(ord(str[1]))[2:4]+hex(ord(str[2]))[2:4]+hex(ord(str[3]))[2:4], 16)

CM_TYPE_INT = StringToID('vint')

CM_VALUE_VAL = StringToID('valu')
CM_VALUE_FORMAT = StringToID('frmt')
CM_VALUE_MIN = StringToID('mini')
CM_VALUE_MAX = StringToID('maxi')
CM_VALUE_MIN2 = StringToID('min2')
CM_VALUE_MAX2 = StringToID('max2')
CM_VALUE_STEP = StringToID('step')
CM_VALUE_TRISTATE = StringToID('tris')

def SetInt32(dlg, id, value, min=-sys.maxint-1, max=sys.maxint, step=1, tristate=0, min2=-sys.maxint-1, max2=sys.maxint):

  msg = c4d.BaseContainer(CM_TYPE_INT)
  msg[CM_VALUE_VAL] = value
  msg[CM_VALUE_FORMAT] = c4d.FORMAT_INT
  msg[CM_VALUE_MIN] = min
  msg[CM_VALUE_MAX] = max
  msg[CM_VALUE_STEP] = step
  msg[CM_VALUE_TRISTATE] = tristate
  if min2 != -sys.maxint-1 or max2 != sys.maxint:
    msg[CM_VALUE_MIN2] = min2
    msg[CM_VALUE_MAX2] = max2

  return dlg.SendMessage(id, msg) != 0

Call this SetInt32() from the subdialog to initialize any integer value.
Note c4d.MINLONGl and c4d.MAXLONGl are no longer used internally. The documentation has to be updated.

Former MAXON SDK Engineer

See here: https://developers.maxon.net/docs/Cinema4DCPPSDK/html/page_list_of_name_changes_in_r15_api.html
There has probably changed more than the names only.

@mp5gosu thanks for your reply, but this error appears also with new names like SetInt32

Checkout my python tutorials, plugins, scripts, xpresso presets and more
https://mikeudin.net

Oh, didn't notice you're working with python. I'll take a look into it later.

Hey there,

I tried to replicate you issue but wasn't able to.
Here's some code I used and everything works as expected:

import c4d
from c4d import gui

var = float(2520.023)

class myDlg(gui.GeDialog):
    def Execute(doc):
        print "Hi"
        return true
    
    def CreateLayout(self):
        self.AddEditNumberArrows(1001, c4d.BFH_SCALEFIT | c4d.BFH_SCALEFIT, initw=70, inith=40 )
        return True

    def InitValues(self):
        self.SetInt32(1001,int(var),min=0, max=c4d.MAXLONGl, step=1, tristate=False, min2=0, max2=c4d.MAXLONGl)
        return True
    
    
def main():
    dlg = myDlg()
    dlg.Open(dlgtype=c4d.DLG_TYPE_MODAL, pluginid=1050902, defaultw=400, defaulth=32)


if __name__=='__main__':
    main()

I have some questions about your code:

  • what type is var of?
  • when are you calling your code to set the parameters?
  • does it also happen when you replace (int)var with a hardcoded value?

Cheers,
Robert

Hi,

The OverFlow error is thrown when SetInt32() is called from a SubDialog (used for Tool plugins settings).
I'm afraid a regression was introduced in R20. It will be fixed in the next update.

The workaround in R20 is to perform in Python what GeDialog::SetInt32() does in the C++ API (see cinema.framework/source/c4d_gui.cpp).

import sys

def StringToID(str):
  return int('0x'+hex(ord(str[0]))[2:4]+hex(ord(str[1]))[2:4]+hex(ord(str[2]))[2:4]+hex(ord(str[3]))[2:4], 16)

CM_TYPE_INT = StringToID('vint')

CM_VALUE_VAL = StringToID('valu')
CM_VALUE_FORMAT = StringToID('frmt')
CM_VALUE_MIN = StringToID('mini')
CM_VALUE_MAX = StringToID('maxi')
CM_VALUE_MIN2 = StringToID('min2')
CM_VALUE_MAX2 = StringToID('max2')
CM_VALUE_STEP = StringToID('step')
CM_VALUE_TRISTATE = StringToID('tris')

def SetInt32(dlg, id, value, min=-sys.maxint-1, max=sys.maxint, step=1, tristate=0, min2=-sys.maxint-1, max2=sys.maxint):

  msg = c4d.BaseContainer(CM_TYPE_INT)
  msg[CM_VALUE_VAL] = value
  msg[CM_VALUE_FORMAT] = c4d.FORMAT_INT
  msg[CM_VALUE_MIN] = min
  msg[CM_VALUE_MAX] = max
  msg[CM_VALUE_STEP] = step
  msg[CM_VALUE_TRISTATE] = tristate
  if min2 != -sys.maxint-1 or max2 != sys.maxint:
    msg[CM_VALUE_MIN2] = min2
    msg[CM_VALUE_MAX2] = max2

  return dlg.SendMessage(id, msg) != 0

Call this SetInt32() from the subdialog to initialize any integer value.
Note c4d.MINLONGl and c4d.MAXLONGl are no longer used internally. The documentation has to be updated.

Former MAXON SDK Engineer

Hi @mikeudin,

I'm wondering if your question has been answered. If so, please mark this thread as solved.

Cheers,
Yannick

Former MAXON SDK Engineer