Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python 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

    Get Decimal/Floating Values On Current Frames Divided by FPS?

    Cinema 4D SDK
    r21 python
    3
    7
    731
    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.
    • B
      bentraje
      last edited by

      Hi,

      Is it possible to get decimal/floating values when current frames is divided by FPS?

      For instance, on a current frame of 12. FPS of 24.
      Currently, it results to 0. I want it to be 0.5.

      Here is the working code:

      import c4d
      fps= doc.GetFps()
      base_time = doc.GetTime()
      frame = base_time.GetFrame(fps)
      time_ratio = frame/fps
      print time_ratio
      

      Thank you for looking at my problem

      1 Reply Last reply Reply Quote 0
      • M
        mp5gosu
        last edited by mp5gosu

        You might have to cast them to float before division. This is a known problem in Python 2.
        You could simply do a

        time_ratio = frame/(fps * 1.0)
        

        Alternatively, you could simply use from __future__ import division but since we are in C4d environment, that might or might not work. - wrong, since this works only from 2.2 and up, not 2.17.

        1 Reply Last reply Reply Quote 1
        • ManuelM
          Manuel
          last edited by

          hi,

          that's the "problem" with python you have to be careful with your type.
          Here, you are dividing an int by another int so the result will be a int. (and a int of 0.4 is 0)

          If you type instead frame/float(fps) python will create a new float variable for fps.
          now you are dividing an int by a float so python return the result as a float.

          Cheers,
          Manuel

          MAXON SDK Specialist

          MAXON Registered Developer

          M 1 Reply Last reply Reply Quote 1
          • B
            bentraje
            last edited by

            Thank you all. Works as expected.

            1 Reply Last reply Reply Quote 0
            • ManuelM
              Manuel
              last edited by

              hi,

              just for your information in this page you can see the Mapping Operators to Functions table.
              also this link
              This inform you that in python 3, the default / will do a real div while if you want a floor div you will need to use //

              Cheers,
              Manuel

              MAXON SDK Specialist

              MAXON Registered Developer

              1 Reply Last reply Reply Quote 1
              • M
                mp5gosu @Manuel
                last edited by

                @m_magalhaes said in Get Decimal/Floating Values On Current Frames Divided by FPS?:

                If you type instead frame/float(fps) python will create a new float variable for fps.

                Although not likely in this case, casting the number may result in a TypeError if the number is a complex number.

                1 Reply Last reply Reply Quote 2
                • ManuelM
                  Manuel
                  last edited by Manuel

                  @mp5gosu thanks for the addition.

                  Cheers,
                  Manuel

                  MAXON SDK Specialist

                  MAXON Registered Developer

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