Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    How to add PLA keyframes

    Scheduled Pinned Locked Moved PYTHON Development
    3 Posts 0 Posters 909 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H Offline
      Helper
      last edited by

      THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

      On 24/03/2011 at 14:15, xxxxxxxx wrote:

      I'm trying to import obj files one for each frame, and add PLA keyframes in C4D, but am not finding anyway to do it using python.  Is this even the right way to approach this problem?

      I'm using C4D R12, trying to import cloth animation from massive.

      1 Reply Last reply Reply Quote 0
      • H Offline
        Helper
        last edited by

        THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

        On 29/03/2011 at 17:38, xxxxxxxx wrote:

        So after three days of pain and suffering through bad docs and C++ decoding, I have a python solution.

        import c4d
        from c4d import utils
        import os

        DEBUG = True
        BUILDFLAGS_0 = 0

        def main() :
            '''Updates an objects keyframes for all frames'''

        #get the object to animate
            obj = doc.SearchObject('Cube')

        #get the pla track Description id
            id = c4d.DescID(c4d.DescLevel(c4d.CTpla, c4d.CTpla, 0))

        # check if track already exist

        plaTrack = obj.FindTrack(id)

        if plaTrack == None:

        #Create the pla track
            plaTrack = c4d.CTrack(obj, id)
            obj.InsertTrackSorted(plaTrack)

        else:

        plaTrack.FlushKeys()

        ctime = doc.GetTime() #save current time

        fps = doc.GetFps()
            start = doc.GetMinTime().GetFrame(fps)  #set min time
            until  = doc.GetMaxTime().GetFrame(fps) #set max time

        #get the plaTrack curve
            myCurve = plaTrack.GetCurve()

        #setup SendModelingCommand base container
            settings = c4d.BaseContainer()
            settings.SetBool(c4d.MDATA_CURRENTSTATETOOBJECT_INHERITANCE, True)
            settings.SetBool(c4d.MDATA_CURRENTSTATETOOBJECT_KEEPANIMATION, False);

        # loop thru each frame
            for f in xrange(start, until) :

        #set the next frame
                time = c4d.BaseTime(f, fps)
                doc.SetTime(time)
                doc.ExecutePasses(None, True, True, True, BUILDFLAGS_0);

        #update timeline
                c4d.GeSyncMessage(c4d.EVMSG_TIMECHANGED)

        #create new object
                newobjList = utils.SendModelingCommand(
                                    command = c4d.MCOMMAND_CURRENTSTATETOOBJECT,
                                    list= [obj],
                                    mode=c4d.MODELINGCOMMANDMODE_ALL,     # mode
                                    bc=settings,
                                    doc = doc)

        newObj = newobjList[0]

        if newObj != None:

        #get the points from the new object
                    points = newObj.GetAllPoints()

        #add the key frame
                    dictKey = myCurve.AddKey(time)
                    key = dictKey["key"]

        #modify points for current frame
                    points[3].x = points[3].x + 25.0
                    newObj.SetAllPoints(points)
                    newObj.Message(c4d.MSG_UPDATE)

        #sync key frame with point data
                    fillSuccess = plaTrack.FillKey(doc,newObj,key)
                    if fillSuccess == False:
                        print('Fill key failed for frame {0}'.format(f))

        else:
                    print('CURRENTSTATETOOBJECT failed to create new object')

        1 Reply Last reply Reply Quote 0
        • H Offline
          Helper
          last edited by

          THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

          On 30/03/2011 at 12:11, xxxxxxxx wrote:

          Thanks for posting your solution! I hope more people would do it 🙂
          I know it can be frustrating at times, but the end result is worth it.

          1 Reply Last reply Reply Quote 0
          • First post
            Last post