Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    StringToNumber to BaseTime

    Cinema 4D SDK
    python
    3
    6
    627
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • mikeudinM
      mikeudin
      last edited by

      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!

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

      ferdinandF 1 Reply Last reply Reply Quote 0
      • ferdinandF
        ferdinand @mikeudin
        last edited by ferdinand

        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
        

        MAXON SDK Specialist
        developers.maxon.net

        1 Reply Last reply Reply Quote 0
        • fwilleke80F
          fwilleke80
          last edited by

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

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

          www.frankwilleke.de
          Only asking personal code questions here.

          1 Reply Last reply Reply Quote 0
          • ferdinandF
            ferdinand
            last edited by

            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.

            MAXON SDK Specialist
            developers.maxon.net

            1 Reply Last reply Reply Quote 0
            • fwilleke80F
              fwilleke80
              last edited by

              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.

              www.frankwilleke.de
              Only asking personal code questions here.

              1 Reply Last reply Reply Quote 0
              • mikeudinM
                mikeudin
                last edited by

                Great, thank you guys!

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

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post