keyframe an object in conjunction to another

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

On 17/04/2012 at 02:41, xxxxxxxx wrote:

User Information:
Cinema 4D Version:   13 
Platform:      Mac OSX  ; 
Language(s) :   C.O.F.F.E.E  ;

---------
Hi there,

I have a problem with a script i've been working on. It is supposed to key object B if object A gets keyed using autmatic keyframing. therefore the script listens if at the current frame object A gets keyed and then uses a callcommand(12410) to keyframe object B.

this works fine if i put the script in the scriptmanager and execute it manualy. but if i put it in a coffeetag so that it should execute automatically, it only works if object A already has had a key on this frame.

hope that was understandable

so heres the code:

main(doc,op)  
{  
  if (op == doc->GetActiveObject()){  
      var time = doc->GetTime();  
      var fps= doc->GetFps();  
      var currentFrame = time->GetFrame(fps);  
      var track = op->GetFirstCTrack();  
      var abordwhile;  
        
      while (track && abordwhile!=true)// iterate through all recorded tracks  
      {  
          if (track->GetName() == "Position . X" || track->GetName() == "Rotation . H") //only for position and rotation tracks  
          {  
              var curve = track->GetCurve(CCURVE_CURVE, FALSE); //Find the curve on a track  
              var keyTotal = curve->GetKeyCount();// count how many keys are on the track  
              var k;  
              for(k=0; k<(keyTotal); k++)// iterating through the keys to find which is on the current frame  
              {  
                  var keytime = curve->GetKey(k)->GetTime()->GetFrame(fps);// get the frame K is on  
                  if (keytime==currentFrame)// if the frame key k is on is the same frame the slider is on  
                  {  
                      k = keyTotal; // set k equal to the total number of keys on the track to stop the iteration through the keys  
                      abordwhile = true; // stop iterating through the tracks  
                      var Keythis1=doc->FindObject("Keythis"); //get the object, set it active and key it  
                      if (Keythis1){  
                          doc->SetActiveObject(Keythis1);                              
                          CallCommand(12410);      
                          println("there should be a key now");  
                          doc->SetActiveObject(op);              
                      }  
                  }  
              }  
          }  
          track = track->GetNext();// go on and do the same thing to the next track until no more tracks are found  
      }  
  }   
}

Thanx,
Bonzo

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

On 17/04/2012 at 05:43, xxxxxxxx wrote:

i guess the callcommand() is colliding ith the editor playback. this is how i would do it in python :

import c4d
from c4d import documents
  
def main() :
    objA = doc.SearchObject("A")
    objB = doc.SearchObject("B")
    t = doc.GetTime()
    
    if (objA != None and objB!= None) :
        if hasKey(objA, t, ["Position . X","Rotation . H"]) :
            setKey(objB, t, ["X-Ray"])
                    
def hasKey (obj, time, tracknames) :
    for track in obj.GetCTracks() :
        for name in tracknames :
            if (name == track.GetName()) :
                if (track.GetCurve().FindKey(time) != None) :
                    print 'Found key on {0}.{1} at {2}'.format(obj.GetName(), name, time.Get())
                    return True
    return False
  
def setKey (obj, time, tracknames) :
    for track in obj.GetCTracks() :
        for name in tracknames :
            if (name == track.GetName()) : 
                curve = track.GetCurve()
                if (curve.FindKey(time) == None) :
                    key = c4d.CKey()
                    key.SetTime(curve, time)
	            # as i am not sure how your key values are driven, you have to add some logic here
                    key.SetValue(curve, 0)
                    curve.InsertKey(key)
                    print 'Added key on {0}.{1} at {2}'.format(obj.GetName(), name, time.Get())

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

On 17/04/2012 at 07:51, xxxxxxxx wrote:

wow thank you. that is exactly what i was going for. only that yours is working 😉

seems like i should dive more into python.

thank you again!

cheers,
Bonzo