Hi!
I’m so happy that I’m working with Blender daily. More then work I’m learning a lot, and is my pleasure and almost obligation to share it back to the community.
Today I needed to animate the years along the frames in an animation. I couldn’t find anything in the forums so I decided to code it. I used Yorik’s parametric dimension as start point.
import Blender as B
def when (frame, years):
iniY = 0
for y in range(len(years)):
if frame > years[y][1]:
iniY = y
iniYear = years[iniY][0]
iniFrame = years[iniY][1]
iniFrameDelay = years[iniY][2]
finYear = years[iniY+1][0]
finFrame = years[(iniY+1)][1]
frameRange = finFrame - (iniFrame + iniFrameDelay)
yearRange = finYear - iniYear
normFrame = float(frame - iniFrame - iniFrameDelay)
normFrame = normFrame/frameRange
if normFrame > 0:
newYear = str(int(iniYear + (yearRange * normFrame)))
else:
newYear = iniYear
return str(newYear)
if B.bylink:
actualFrame = B.Get("curframe")
year = B.link
dynYear = year.getData()
Years = []
# year = [year, initial frame, duration of frames]
Years.append([1800, 1, 10])
Years.append([1850, 100, 50])
Years.append([1994, 170, 100])
Years.append([2008, 300, 50])
Years.append([2050, 400, 50])
oldYear=dynYear.getText()
newYear=when (actualFrame,Years)
if newYear != oldYear:
dynYear.setText(newYear)
year.makeDisplayList()
B.Window.RedrawAll()
To use this script you should create an object Text, Enable Scripts Link to this this object and link this script to the event Frame Change. To change the years you just need to change these lines:
# year = [year, initial frame, duration of frames]
Years.append([1800, 1, 10])
Years.append([1850, 100, 50])
Years.append([1994, 170, 100])
Years.append([2008, 300, 50])
Years.append([2050, 400, 50])
Adding the year, the initial frame to this year, and the duration of of this year in frames.
Released to Blender 2.46, but probably works in old versions.
Fell free to use, change, comment, share, …
Great hugs,
Dalai Felinto