PluginCafe / cinema4d_py_sdk

The official Cinema 4D Python examples.
https://developers.maxon.net/
Apache License 2.0
122 stars 43 forks source link

Example for creating animation tracks #1

Open NiklasRosenstein opened 8 years ago

NiklasRosenstein commented 8 years ago

Is missing from what I can see

andreasblock commented 8 years ago

Hi Niklas, not quite sure, if you want to make us aware, that we forgot to upload an example to GitHub, or if you are requesting a new example on this topic. In the later case, I suggest to come over to the Plugin Cafe forums, so we can discuss your problems there. A new example might emerge from that discussion later on. Cheers, Andreas

NiklasRosenstein commented 8 years ago

Hi Andreas, sorry I was a bit in a hurry to put it down. :smile: As far as I can see there is no example in the SDK or SDK documentation that shows how to create animations (tracks & keys). Here's a quick example snippet, maybe that could be added to the SDK or (much preferably for such short snippets) the documentation.

import c4d, math

def main():
    # Create the DescID of the relative X position.
    desc_id = c4d.DescID(
        c4d.DescLevel(c4d.ID_BASEOBJECT_REL_POSITION, c4d.DTYPE_VECTOR, 0),
        c4d.DescLevel(c4d.VECTOR_X, c4d.DTYPE_REAL, 0)
    )

    # Find the animation track or create one.
    track = op.FindCTrack(desc_id)
    if not track:
        track = c4d.CTrack(op, desc_id)
        op.InsertTrackSorted(track)
        doc.AddUndo(c4d.UNDOTYPE_NEW, track)
        undo_keys = False
    else:
        undo_keys = True

    # Create the keys.
    curve = track.GetCurve()
    fps = doc.GetFps()
    for i in xrange(100):
        key = curve.AddKey(c4d.BaseTime(i, fps))['key']
        key.SetValue(curve, math.sin(i / 100.0 * math.pi) * 100)
        if undo_keys:
            doc.AddUndo(c4d.UNDOTYPE_NEW, key)

    c4d.EventAdd()

if __name__ == "__main__":
    main()
andreasblock commented 8 years ago

Hi Niklas, thank you very much for your example. Actually we are working on documentation and examples and we are trying to achieve a closer connection between actual documentation and examples. So I can't promise your example will actually make it into the documentation. But don't get me wrong, we appreciate your input very much. It's just that we might come to the conclusion our own examples fit the surrounding documentation a bit better. But the final decision hasn't been made, yet. In any case, if we use your example, you'll be given credit. And I really hope, you don't mind, if we come up with something else. Cheers, Andreas

NiklasRosenstein commented 8 years ago

Sure, do whatever you think is best for the docs. :) Two things I still want to ask

andreasblock commented 8 years ago

If you are asking that way, we'd rather receive requests about documentation over in the Plugin Café forums. Just to have it all in one place. We currently have no plans to release the source of the documentation here. We'll happily receive and integrate any change requests we receive through the usual channels, though.