Skip to content

Instantly share code, notes, and snippets.

/SimpleMover.py
Created Mar 13, 2018

Embed
What would you like to do?
Simple Mover C4D Python Expression Tag
"""Name-US: Simple Mover
Description-US: Expression Tag that Moves and Object Over Time
Version History
===============
v0.0.1 - Initial Version
Copyright (C) 2018 Maxon Computer Inc.
Written for Cineversity.com
Written by Donovan Keith <donovanskeith@gmail.com>
"""
import c4d
def GetValueAtTime(start, rate, time, offset=0.0):
"""Calculates PSR for rate at time. If vector is 0
for a given channel (XYZ, HPB), then start will be returned."""
value_at_time = start
if rate.x:
value_at_time.x = rate.x * time + offset
if rate.y:
value_at_time.y = rate.y * time + offset
if rate.z:
value_at_time.z = rate.z * time + offset
return value_at_time
def main():
obj = op.GetObject()
if obj is None:
return
# Get a direction/trajectory from the user
move = op[c4d.ID_USERDATA,1]
rotate = op[c4d.ID_USERDATA,2]
scale = op[c4d.ID_USERDATA,3]
# Get the time in seconds
time = doc.GetTime().Get()
# Position
start_pos = obj.GetRelPos()
new_pos = GetValueAtTime(start_pos, move, time)
obj.SetRelPos(new_pos)
# Scale
start_scale = obj.GetRelScale()
default_scale = 1.0 #Don't start from 0 scale.
new_scale = GetValueAtTime(start_scale, scale, time, offset=default_scale)
obj.SetRelScale(new_scale)
# Rotation
start_rot = obj.GetRelRot()
new_rot = GetValueAtTime(start_rot, rotate, time)
obj.SetRelRot(new_rot)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.