Questions regarding Keys/CKey[SOLVED]



  • On 04/04/2015 at 01:12, xxxxxxxx wrote:

    There's certain attributes on keys that I'm not 100% sure how to access via python, and I'm wondering if anyone knows how.

    If you select a key in the Powerslider or Timeline, in the AM, there are lots of checkboxes for things like Clamp, Auto Tangents, etc. How do you get/set those values via python?

    Follow up but not really related question, key.GetValue() only works on floats. So if you were to key say a drop down, value would always return as 0.0. What's the proper way to get/set those values in instances like that? Does it have to then be done via obj[c4d.AttrName] instead? Is there an easy way to know via python when one needs to do that? I'm trying to create a dictionary with the values, of each key, but I don't know how to know when I can just use key.value and when and how to get it when it's not a float value.

    Can anyone point me in the right direction?



  • On 04/04/2015 at 03:07, xxxxxxxx wrote:

    Hello,

    if it´s not a float key/ctrack and not one off the c4d special ctracks (c4d.CTrack Link)
    you can set up a descid with the attribute and an appropriate datatype.
    After that you can add , fill the key and set the data with .SetGeData().
    The attributes of the key can be defined with e.g. CKey.SetInterpolation( seq , inter )
    You´ll find some mor informations here:
    CKey

    A simple example with a stage object and a camera key:

    Hope this helps
    Best wishes
    Martin

      
    import c4d  
    from c4d import gui  
      
      
      
    def main() :  
      #_______________________________  
      #stage object example  
      frontCam = c4d.BaseObject(c4d.Ocamera)  
      frontCam[c4d.CAMERA_PROJECTION] = 4  
      frontCam[c4d.CAMERA_ZOOM] = 300  
      frontCam.SetName("FrontCam")  
        
      stage = c4d.BaseObject(c4d.Ostage)  
      doc.InsertObject(stage)  
      doc.InsertObject(frontCam)  
      #set up attribute descid with appropriate datatyp / insert Ctrack / get the curve  
      descid = c4d.DescID(c4d.DescLevel(c4d.STAGEOBJECT_CLINK,c4d.DTYPE_BASELISTLINK))  
      track = c4d.CTrack(stage,descid)  
      stage.InsertTrackSorted(track)          
      curve = track.GetCurve()    
      
      #choose time and set value  
      frame = 3  
      fps = doc.GetFps()   
      keyTime = c4d.BaseTime(frame,fps)  
      
      
      #try adding a key  
      addCam = curve.AddKey(keyTime)  
      if addCam:  
          keyCam = addCam["key"]  
          track.FillKey(doc, stage, keyCam)  
        
      #set data to key  
      keyCam.SetGeData(curve, frontCam)  
      #data from the key  
      print keyCam.GetGeData()  
        
      #set timing for the key / in this case smoothing doesn´t make sense  
      keyCam.SetInterpolation(curve, c4d.CINTERPOLATION_STEP)  
      
      c4d.EventAdd()   
    if __name__=='__main__':  
      main()  
    


  • On 04/04/2015 at 12:10, xxxxxxxx wrote:

    Thank you for the example. That provides a bit of clarity to some parts.

    So my follow up question is then, is it better to use the method of getting the value of a key by the description id you posted? Can that be used on Floats as well? Is there any benefit to doing it this way vs. not doing it this way? I'm trying to write something that will store all the animation on an object to a file, so I need consistent ways of gathering the data for a wide variety of track types(Though probably excluding the 4 special CTrack Types). So would it be better to get and set the data regardless of whether or not it's a float using the method you showed?

    Yes, I see that key.SetInterpolation, but there is still a variety of key ID's that are not available naturally through CKey, and I'm wondering how/where I can find them. The attributes im trying to be able to get/set are: LockTime, LockValue, Mute, MakeRelative, AutoTangents, Clamp, LockAngles, LockLengths, BreakTangents, and KeepVisualAngle. Not every key type has those options, but if a key does, I need to be able to get that information and store it, so that when reapplying the animation its as true as can be to the original.



  • On 06/04/2015 at 05:49, xxxxxxxx wrote:

    it´s important to separate the different kinds of tracks.
    with GetValue() you want get int and other types as you already know and with GetGeData() every float type is a none.
    There is a method to separate the tracks accordingly to their type.
    Ctrack.GetTrackCategory()

      
    def main() :  
      #get all keys for an object at a certain time  
      frame = 3  
      fps = doc.GetFps()   
      keyTime = c4d.BaseTime(frame,fps)  
        
      tracks = op.GetCTracks()  
      keyValues = []  
      print tracks  
      for t in tracks:  
            
          curve = t.GetCurve()   
          key = curve.FindKey(keyTime, c4d.FINDANIM_EXACT)  
          if not key:continue  
            
          if t.GetTrackCategory() == c4d.CTRACK_CATEGORY_VALUE:  
              print "value_track"  
              keyvalue = curve.GetValue(keyTime, fps)  
              keyValues.append(keyvalue)  
          elif t.GetTrackCategory() == c4d.CTRACK_CATEGORY_DATA:  
              print "data_track"  
              keydata = key['key'].GetGeData()  
              keyValues.append(keydata)  
          else:  
              print "plugin_track"  
    

    To your other question:
    the only thing I know is, I can´t find them, too

    Best wishes
    Martin



  • On 07/04/2015 at 09:09, xxxxxxxx wrote:

    Hello,

    the key parameters are defined in the ckvalue.res resource file (or here). You can access these parameters like any other parameter:

      
    print key[c4d.ID_CKEY_CLAMP]  
    

    best wishes,
    Sebastian



  • On 08/04/2015 at 23:44, xxxxxxxx wrote:

    Thanks Martin and Sebastian. This has gotten me much further than ever before.



  • On 09/04/2015 at 02:53, xxxxxxxx wrote:

    Hello,

    @xfon5168
    I´m glad I could help a little.

    @Sebastian
    Thanks for the hint, always forget searching the c++ sdk.
    Is there a reason why we can´t drag and drop the key attributes to the script editor like any other parameter?

    Best wishes
    Martin



  • On 09/04/2015 at 05:31, xxxxxxxx wrote:

    Hello,

    for some internal technical reasons it is not possible to drag&drop key parameters into the script editor.

    Best wishes,
    Sebastian


Log in to reply