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

    Drive smooth rotation

    Cinema 4D SDK
    3
    3
    575
    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.
    • PMenichP
      PMenich
      last edited by ferdinand

      Hey, I've been trying to create a python node in xpresso to emulate this bit of code from the amazing Mr Ebberts...

      http://motionscript.com/articles/speed-control.html

      Here's the After Effects expression I'm trying to translate...

      spd = effect("Slider Control")("Slider");
      n = spd.numKeys;
      if (n > 0 && spd.key(1).time < time){
        accum = spd.key(1).value*(spd.key(1).time - inPoint);
        for (i = 2; i <= n; i++){
          if (spd.key(i).time > time) break;
          k1 = spd.key(i-1);
          k2 = spd.key(i);
          accum += (k1.value + k2.value)*(k2.time - k1.time)/2;
        }
        accum += (spd.value + spd.key(i-1).value)*(time - spd.key(i-1).time)/2;
      }else{
        accum = spd.value*(time - inPoint);
      }
      value + accum
      

      Here's where I'm at with my Python translation...

      from typing import Optional
      import c4d
      
      op: c4d.modules.graphview.GvNode # The Xpresso node
      doc: c4d.documents.BaseDocument # The document evaluating this node
      tp: Optional[c4d.modules.thinkingparticles.TP_MasterSystem] # Particle system
      
      def main():
          global Output1
          #Grab the host-object to the xpresso Tag
          Rect = op.GetNodeMaster().GetOwner().GetObject()
      
          #Get the UserData
          spd = Rect[c4d.ID_USERDATA,1]
      
          # Get the first animation track of the object
          track = Rect.GetFirstCTrack()
      
          # Get the animation curve of the track
          curve = track.GetCurve()
      
          # Get the number of keyframes on the curve
          n = curve.GetKeyCount()
      
          fps   = doc.GetFps()
          sFrame= doc.GetMinTime().GetFrame(fps)
          eFrame= doc.GetMaxTime().GetFrame(fps)
          name  = op.GetName()
          key = curve.GetKey(1)
          keyValue = key.GetValue()
          keyFrame = key.GetTime().GetFrame(fps)
          currentFrame = doc.GetTime().GetFrame(doc.GetFps())
          value = spd
      
      
        
          if n > 0 and curve.GetKey(1).GetTime().GetFrame(fps) < currentFrame:
              accum = curve.GetKey(1).GetValue() * (curve.GetKey(1).GetTime().Get() - sFrame)
              for i in range(2, n):
                  if curve.GetKey(i).GetTime().Get() > currentFrame:
                      break
                  k1 = curve.GetKey(i-1)
                  k2 = curve.GetKey(i)
                  accum += (k1.GetValue() + k2.GetValue()) * (k2.GetTime().Get() - k1.GetTime().Get()) / 2
              accum += (curve.GetValue(curve.GetKey(i-1).GetTime()) + curve.GetKey(i-1).GetValue()) * (currentFrame - curve.GetKey(i-1).GetTime().Get()) / 2
          else:
              accum = Input1 * (currentFrame - sFrame)
          
          print(Input1 + accum)
      
          Output1 = value + accum
      
      • There are loads of unnecessary variables in there btw - that was me just trying to figure this stuff out!

      Basically trying to drive rotation without using time as my driver. Now, I'm no programmer (as you'll soon find out!), but the attached project does work, but doesn't do what I want it to! When the UsrData 'speed' gets to 0 it should stop. And the rotation is meant to be smooth ramp up and then smooth ramp down.

      Any python geniuses out there got time to take a look and tell me where I'm going wrong?

      Smooth_Rotater.c4d

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

        Hi @PMenich first of all welcome to the plugincafe forum.

        If you want to embed code in your topic you should use the code markup which consist of 3 `. So you need to do ``` Your Code ``` this way your topic will be more readable, Ferdinand did cleanup your topic.

        Regarding your initial question, I would like to let you know this is out of scope of Maxon support according to our Forum and Support Guidelines and we cannot debug your code for you, so it will be up to the community to provide an answers.

        Cheers,
        Maxime.

        MAXON SDK Specialist

        Development Blog, MAXON Registered Developer

        J 1 Reply Last reply Reply Quote 0
        • J
          jana @m_adam
          last edited by

          Hello @PMenich ,

          without further questions or postings, we will consider this topic as solved by Friday, the 11th of august 2023 and flag it accordingly.

          Thank you for your understanding,
          Maxon SDK Group

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