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

    Apply a step value in SetHandle function

    Cinema 4D SDK
    python
    2
    4
    460
    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.
    • mfersaouiM
      mfersaoui
      last edited by mfersaoui

      Hi,

      REAL MYOBJECT_HEIGHT { UNIT METER; CUSTOMGUI REALSLIDER; MIN 0; MAXSLIDER 200.0; STEP 20;}
      

      I have an object that have a Description Resource element with "20" as STEP value and I want to apply the STEP value on the height value of the SetHandle() function

      def SetHandle(self, op, handle_index, handle_position, info):
      
              handle_origin = HandleInfo()
              self.GetHandle(op, handle_index, handle_origin)
              
              data = op.GetDataInstance()
              if data is None or not self.handle:
                  return 
      
              height      = data.GetFloat(c4d.LKC_KINOFLO_HEIGHT)
      
              value = (handle_position - handle_origin.position) * info.direction
      
              if handle_index == 0:
                  op[c4d.MYOBJECT_HEIGHT] += value
      

      Thanks.

      mfersaouiM 1 Reply Last reply Reply Quote 0
      • mfersaouiM
        mfersaoui @mfersaoui
        last edited by mfersaoui

        @mfersaoui
        I found something like this:

        op[c4d.MYOBJECT_HEIGHT] += value
        mod = op[c4d.MYOBJECT_HEIGHT] % 20
        op[c4d.MYOBJECT_HEIGHT] = op[c4d.MYOBJECT_HEIGHT] if mod == 0 else (op[c4d.MYOBJECT_HEIGHT] - mod) + 20
        
        1 Reply Last reply Reply Quote 0
        • ferdinandF
          ferdinand
          last edited by ferdinand

          Hi,

          this is probably a question of taste, but to me your solution seems a bit complicated. A quantized value can be expressed just as quant_value = int(value / stride) * stride, where value and stride are floating point values. You can replace int with math.floor or math.ceil if you do not want to round to the closest neighbour, but always to the lower or higher neighbour.

          Cheers,
          zipit

          MAXON SDK Specialist
          developers.maxon.net

          mfersaouiM 1 Reply Last reply Reply Quote 2
          • mfersaouiM
            mfersaoui @ferdinand
            last edited by

            @zipit
            Hi,
            Thank you.

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