SOLVED StringToNumber to BaseTime

Hi guys!
Is it possible to convert string value to BaseTime with this function?

Converts a string to a data value of type float, int or c4d.BaseTime.

>>> c4d.utils.StringToNumber('11', c4d.FORMAT_FRAMES, doc.GetFps())
11.0
>>> c4d.utils.StringToNumber('11', c4d.FORMAT_SECONDS, doc.GetFps())
11.0
>>> c4d.utils.StringToNumber(11, c4d.FORMAT_FRAMES, doc.GetFps())
11.0

After some tests i had no luck with it.😬🤷♂

>>> doc[c4d.DOCUMENT_MINTIME] = c4d.utils.StringToNumber('11', c4d.FORMAT_FRAMES, doc.GetFps())
Traceback (most recent call last):
  File "console", line 1, in <module>
TypeError: __setitem__ expected c4d.BaseTime, not float
>>> 

Thank you!

Hello @mikeudin,

thank you for reaching out to us. I had a look at the C++ backend and the statement you quoted does not seem to be true (anymore). The cases FORMAT_FRAMES, FORMAT_SECONDS and FORMAT_SMPTE all return a float value. So, both the Python and C++ documentation are not correct. I will add a task to fix these issues.

It is not 100% clear to me what you were trying to achieve, but I think this is what you want to do:

>>> import c4d

>>> value = "11"

# This call does not make much sense IMHO. One could just use int() or float() 
# to convert a frame value expressed by a string into a numeric value.
>>> c4d.utils.StringToNumber('11', c4d.FORMAT_FRAMES, doc.GetFps())
11.0
>>> int(value)
11

# Convert a frame-value to a value in seconds for a given document. A BaseTime value is 
# document independent, a value in frames is not, we must provide the FPS.
>>> t = int(value) / doc.GetFps()
>>> doc.GetFps()
30
>>> t
0.36666666666666664

# Pack the value into a BaseTime
>>> bt = c4d.BaseTime(t)
>>> bt
<c4d.BaseTime object at 0x000001C2B9D3E6C0>

>>> bt.Get()
0.367

If you simply want to set the document's min time, why not just do this:

doc[c4d.DOCUMENT_MINTIME] = c4d.BaseTime(11)

If you simply want to set the document's min time, why not just do this ...

Well, the question is what that value is supposed to be. Judging from the context I assumed it to be a value in frames and not seconds. Your BaseTime would be equal to frame 330 for a document with 30 FPS. And also, the input is meant to be a string.

Oh, ok. I assumed he just wanted to set the document min time and didn't know a better way to get a BaseTime than using StringToNumber.

Great, thank you guys!