WotS

02 February 2013, 12:02 AM

Hello.

This is one of the most useful scripts for After Effects, that adds oscillatory train to any animated property.

n = 0;

if (numKeys > 0){

n = nearestKey(time).index;

if (key(n).time > time){

n--;

}

}

if (n == 0){

t = 0;

}else{

t = time - key(n).time;

}

if (n > 0){

v = velocityAtTime(key(n).time - thisComp.frameDuration/10);

amp = .5;

freq = 4.0;

decay = 2.0;

value + v*amp*Math.sin(freq*t*2*Math.PI)/Math.exp(decay*t);

}else{

value;

}

Script can be added as expression to any property move, size, rotation, opacity, color, etc - and influence this feature with the keys, adding oscillatory train in the end. So, I'm trying to write this script on Python in Cinema 4D. And here is what I got.

import math

import c4d

#Welcome to the world of Python

def main():

obj = doc.SearchObject("Test_Cube")

track = obj.GetFirstCTrack()

curve = track.GetCurve()

numkeys = curve.GetKeyCount()

n = 0

time = doc.GetTime()

fps = doc.GetFps()

curFrame = time.GetFrame(fps)

lst = []

for i in range(0, numkeys):

key = curve.GetKey(i).GetValue()

keytime = curve.GetKey(i).GetTime().GetFrame(fps)

lst.append(keytime)

lstS = []

for i in range(0,len(lst)):

sub = abs(lst-curFrame)

lstS.append(sub)

for i, j in enumerate(lstS):

if j == min(lstS):

MinInd = i

nearestKey = lst[MinInd]

for i, j in enumerate(lst):

if j == nearestKey:

nearestKeyIndex = i

if numkeys > 0:

n = nearestKeyIndex

if nearestKey > curFrame:

n = n-1

if n == 0:

t = 0

else:

t = curFrame - nearestKey

lastKeyValue = curve.GetKey(numkeys-1).GetValue()

previousKeyValue = curve.GetKey(numkeys-2).GetValue()

curValue = curve.GetValue(time,fps)

if n > 0:

v = (lastKeyValue - previousKeyValue)*fps

amp = 0.5

freq = 4

decay = 2

curValue + v*amp*math.sin(freq*t*2*3.14)/math.exp(decay*t)

else:

curValue

http://cs419629.userapi.com/v419629100/24a8/KbzWb_iTeUs.jpg

In Cinema 4D there are no such functions as [I]nearestKey and velocityAtTime unlike After Effects. My script does not work in Cinema 4D. For writing it I used the Python tag. Compile says "No errors". This script is Executed. But not the desired effect. There is no change in the object's animation. I count on your help guys.

P.S. I am sorry for my bad English

This is one of the most useful scripts for After Effects, that adds oscillatory train to any animated property.

n = 0;

if (numKeys > 0){

n = nearestKey(time).index;

if (key(n).time > time){

n--;

}

}

if (n == 0){

t = 0;

}else{

t = time - key(n).time;

}

if (n > 0){

v = velocityAtTime(key(n).time - thisComp.frameDuration/10);

amp = .5;

freq = 4.0;

decay = 2.0;

value + v*amp*Math.sin(freq*t*2*Math.PI)/Math.exp(decay*t);

}else{

value;

}

Script can be added as expression to any property move, size, rotation, opacity, color, etc - and influence this feature with the keys, adding oscillatory train in the end. So, I'm trying to write this script on Python in Cinema 4D. And here is what I got.

import math

import c4d

#Welcome to the world of Python

def main():

obj = doc.SearchObject("Test_Cube")

track = obj.GetFirstCTrack()

curve = track.GetCurve()

numkeys = curve.GetKeyCount()

n = 0

time = doc.GetTime()

fps = doc.GetFps()

curFrame = time.GetFrame(fps)

lst = []

for i in range(0, numkeys):

key = curve.GetKey(i).GetValue()

keytime = curve.GetKey(i).GetTime().GetFrame(fps)

lst.append(keytime)

lstS = []

for i in range(0,len(lst)):

sub = abs(lst-curFrame)

lstS.append(sub)

for i, j in enumerate(lstS):

if j == min(lstS):

MinInd = i

nearestKey = lst[MinInd]

for i, j in enumerate(lst):

if j == nearestKey:

nearestKeyIndex = i

if numkeys > 0:

n = nearestKeyIndex

if nearestKey > curFrame:

n = n-1

if n == 0:

t = 0

else:

t = curFrame - nearestKey

lastKeyValue = curve.GetKey(numkeys-1).GetValue()

previousKeyValue = curve.GetKey(numkeys-2).GetValue()

curValue = curve.GetValue(time,fps)

if n > 0:

v = (lastKeyValue - previousKeyValue)*fps

amp = 0.5

freq = 4

decay = 2

curValue + v*amp*math.sin(freq*t*2*3.14)/math.exp(decay*t)

else:

curValue

http://cs419629.userapi.com/v419629100/24a8/KbzWb_iTeUs.jpg

In Cinema 4D there are no such functions as [I]nearestKey and velocityAtTime unlike After Effects. My script does not work in Cinema 4D. For writing it I used the Python tag. Compile says "No errors". This script is Executed. But not the desired effect. There is no change in the object's animation. I count on your help guys.

P.S. I am sorry for my bad English