title: How can you check if a frame is a keyframe in Maya with Python?
body: <p>I need to cycle through every frame of an animation in Maya and create two arrays, one of the values of a given attribute at every single frame, and one of those values only at the keyframes. Problem is, I can't figure out how to make maya ask the question "is the current frame a keyframe for this attribute" in python. I figured it out in MEL, though, so maybe somebody could help me convert it.</p>
  
  <p>Here's the loop in MEL:</p>
  
  <pre><code>global proc int keyExistsAtFrame(   int $frameNum,
                      string $object,
                      string $attribute)
  {
      int $value;
      selectKey -clear;
      $value = `selectKey -add -k -t $frameNum ($object + "." + $attribute)`;
  
      if($value)
          return 1;
      else
          return 0;
  }
  
  for( $i=1; $i&lt;120; ++$i )
  {
      currentTime -edit $i;
      if (keyExistsAtFrame($i, "DD_headRoll_ctrl", "rotateZ"))
      {
          print "key exists at ";
          print $i;
          print "\n";
      }
  }
  </code></pre>
  
  <p>How could I implement this into my python script?
  Here's my current draft in python:</p>
  
  <pre><code>import maya.cmds as cmd
  
  for i in range(int(cmd.playbackOptions(q=1, minTime = True)), int(cmd.playbackOptions(q=1, maxTime = True))):
      cmd.currentTime(i, e=1)
      iskey = cmd.selectKey(add = True, k = True, t = (i, i), attribute = "DD_headRoll_ctrl.rotateZ")
      #print iskey
      if iskey:
          print i
  </code></pre>