Forum

Guest  

Show or hide header
Welcome Guest, posting in this forum require registration.




Py4D - the official page » Py4D Developer Forum » SDK Support » How can add a key on object

Pages: [1]
This is the forum for the free Py4D plugin in CINEMA 4D R11.5.
Please visit the forum on PluginCafe to get support for Python in CINEMA 4D R12.
Author Topic: How can add a key on object
Nitroman
Member
Posts: 72
Post How can add a key on object
on: July 26, 2010, 13:49
Quote

Hi
I try make animate a cube with python

From example i have make a cube
and i want in frame 10 add key here with pos Vector(0,0,0)
and in frame 20 add key with pos vector(0,100,0)

how can do this with python if anyone can write simple example

thank you

ScottA
Member
Posts: 18
Post Re: How can add a key on object
on: July 27, 2010, 01:08
Quote

I know how to do this in Coffee a few different ways. But I haven’t tried to convert most of them to python yet.

Here’s one way:

import c4d
from c4d import symbols as sy 

def main():

    obj = doc.SearchObject("Cube")#finds an object named Cube
    time = doc.GetTime()
    fps = doc.GetFps()
    doc.SetTime(c4d.BaseTime(0, fps))
    c4d.CallCommand(12410) # R.ecord A.ctive O.bjects
    c4d.CallCommand(12418) # toggle Scale track off so R.A.O doesn't create empty tracks
    c4d.CallCommand(12419) # toggle Rotation track off so R.A.O doesn't create empty tracks
    obj[sy.ID_BASEOBJECT_POSITION,1001]=0 # the cube's start position
    c4d.CallCommand(12410) # R.ecord A.ctive O.bjects

    doc.SetTime(c4d.BaseTime(20, fps))
    obj[sy.ID_BASEOBJECT_POSITION,1001]=100 # the cube's end position
    c4d.CallCommand(12410) # R.ecord A.ctive O.bjects
    c4d.CallCommand(12418) # toggle scale track back ON
    c4d.CallCommand(12419) # toggle Rotation track back ON

But there seems to be a problem(bug?) in Py4d with the time line not getting updated after the record objects command is used.
This script will ONLY work if the time line is running when you execute it.
Like I said…Something is wrong with the time line not updating properly. Or there’s a special update function that I’m not aware of to fix this problem.
But at least you’ll get the idea of what I’m doing in there.

The other way of doing this in Coffee is to first get the object’s track you want. Then get it’s curve. Then use the record objects command and you can then change the values through the various curve functions.
The big hassle while doing this in Coffee is that there’s no way to create a single key(other than this turning off certain tracks trick I posted above). And all we have to use is the record option to create keys.*YUCK!*
Which then requires a lot of extra work to remove the stuff we didn’t want keyed in the first place. By iterating through the curves and deleting stuff we didn’t want to be keyed using the DelKey() function.

I’d really love to see Sebastian post an example using the Py4D AddKey()function.
That might be a way to get around the time line not updating problem.

-ScottA

Nitroman
Member
Posts: 72
Post Re: How can add a key on object
on: July 27, 2010, 13:50
Quote

hi thank you for the code

for update timeline bar use

c4d.GeSyncMessage(EVMSG_TIMECHANGED)

yes i know this way i don’t want use callcommand
i want use tracks and add keys i hope too Sebastian post something example
how you can do with out use callcommands

Pages: [1]
WP-Forum by: Fredrik Fahlstad, Version: 2.3
Page loaded in: 0.044 seconds.
>