Selected Keys? Move Keys?



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

    On 27/02/2011 at 08:05, xxxxxxxx wrote:

    Trying to move this on in a more modular way
    ie have a  function for each transformation on selected keys

    just wondered if I was heading in the right direction???
    (ignore print checkpoints just for testing)

    Next objective to 'nudge' everything back
    as 'everything' gets moved over by staggering process
    ie first track shouldnt move - everything else - stagger

    #####################################
    Updated version in later post
    


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

    On 01/03/2011 at 00:42, xxxxxxxx wrote:

    Making an effort to understand what I'm seeing

    Line 14 function call within itself - seems incorrect?
           
    MoveSelectedKeys(op,offset,timeln)



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

    On 01/03/2011 at 07:21, xxxxxxxx wrote:

    I am sorry, I may can go to my pc this weekend, but not earlier.

    Does the Console tell you this ? O.o

    If A function calls itself, everything starts again. But you may have changed some values before. (Here the timeln variable)



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

    On 02/03/2011 at 01:03, xxxxxxxx wrote:

    Can anyone tell me why this message 
    doesn't pop up if NO object is selected using the function from the code above?

    lst = GetActiveObjects(doc)
        op = lst[0]
        if not op:
            gui.MessageDialog("No objects selected") 
            return False #leave the script if not an object



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

    On 02/03/2011 at 02:37, xxxxxxxx wrote:

    Dunnoo .. Gonna test this this weekend. Maybe it's because op = lst[0] ist not in the right column ?

      lst = GetActiveObjects(doc)
      op = lst[0] ## here
        if not op:
            gui.MessageDialog("No objects selected") 
            return False #leave the script if not an object
    


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

    On 02/03/2011 at 03:03, xxxxxxxx wrote:

    Hi Nux

    nope, not that - must be forum paste incorrect
    indent is as your example

    appreciate you can't test at moment

    I think its to do with this function setting op to the first object in doc
    if nothing selected
    that way op is never NULL 
    #####################################
    def GetActiveObjects(doc) :
        import c4d
        lst = list()
        op = doc.GetFirstObject()
        while op:
            if op.GetBit(c4d.BIT_ACTIVE) == True: lst.append(op)
            op = GetHNext(op)
        return lst
    #####################################



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

    On 02/03/2011 at 03:22, xxxxxxxx wrote:

    the list only gets appended if op is selected.



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

    On 03/03/2011 at 06:11, xxxxxxxx wrote:

    And this is where I'm at so far

    Ignore some Print items - just for console checks

    Still trying to make it modular
    ie have a function for each type of key transform - (just stagger in this one)
    appreciate any advice on good/bad code form

    added gui to take offset
    count selected objects - need more than 2
    and now first object doesnt get offset (its popped off array)

    #####################################
    def MoveSelectedKeys(op,offset,timeln = 1) :    # offset in frames
        import c4d
      
        if (not op) or (not offset) : return False
      
        if timeln == 1: timeln = c4d.NBIT_TL1_SELECT
        elif timeln == 2: timeln = c4d.NBIT_TL2_SELECT
        elif timeln == 3: timeln = c4d.NBIT_TL3_SELECT
        elif timeln == 4: timeln = c4d.NBIT_TL4_SELECT
        else:
            import math
            timeln = math.fmod(timeln,4)
      
        doc = op.GetDocument()
      
        track = op.GetFirstCTrack()
        if not track: return False
      
        fps = float(doc.GetFps())
      
        while track:
            curve = track.GetCurve()
            cnt = curve.GetKeyCount()
            for i in xrange(cnt) :
                key = curve.GetKey(i)
                if key.GetNBit(int(timeln)) == True:
                    tme = key.GetTime()
                    key.SetTime(curve,c4d.BaseTime(offset/fps+tme.Get()))
            track = track.GetNext()
        c4d.EventAdd(c4d.MSG_UPDATE)
      
        return True
    #####################################
    def GetLastSelectedKey(track, timeln = 1) :
        import c4d
      
        if timeln == 1: timeln = c4d.NBIT_TL1_SELECT
        elif timeln == 2: timeln = c4d.NBIT_TL2_SELECT
        elif timeln == 3: timeln = c4d.NBIT_TL3_SELECT
        elif timeln == 4: timeln = c4d.NBIT_TL4_SELECT
        else:
            import math
            timeln = math.fmod(timeln,4)
      
        curve = track.GetCurve()
        cnt = curve.GetKeyCount()
      
        for i in xrange(cnt) :
            key = curve.GetKey(cnt-i-1)
            if key.GetNBit(int(timeln)) == True:
                return key  
    ####################################MINE
    def GetFirstSelectedKey(track, timeln = 1) :
        import c4d
      
      
        if timeln == 1: timeln = c4d.NBIT_TL1_SELECT
        elif timeln == 2: timeln = c4d.NBIT_TL2_SELECT
        elif timeln == 3: timeln = c4d.NBIT_TL3_SELECT
        elif timeln == 4: timeln = c4d.NBIT_TL4_SELECT
        else:
            import math
            timeln = math.fmod(timeln,4)
      
        curve = track.GetCurve()
        cnt = curve.GetKeyCount()
        key = curve.GetKey(0)
      
        if key.GetNBit(int(timeln)) == True:
            return key 
    #####################################
    def GetHNext(op) :
        if not op: return
        if op.GetDown() : return op.GetDown()
        while not op.GetNext() and op.GetUp() :
            op = op.GetUp()
        return op.GetNext()
    #####################################
    def GetActiveObjects(doc) :
        import c4d
        lst = list()
        op = doc.GetFirstObject()
        while op:
            if op.GetBit(c4d.BIT_ACTIVE) == True: lst.append(op)
            op = GetHNext(op)
        return lst
    #####################################MINE
    def Stagger(doc,op,lst,keylast,overlap) :
        import c4d
        print "Length of list before pop", len(lst) 
        lst.pop(0)  #remove the first object as its not moved
        op = lst[0] #get fist active object again, less original first object
        print "Length of list after pop", len(lst) 
      
     
        offset = keylast.GetTime().GetFrame(doc.GetFps())-overlap
        for i in xrange(len(lst)) : #increment through allthe objects selected
            doc.AddUndo(c4d.UNDOTYPE_CHANGE,op)
            MoveSelectedKeys(op,offset) #moves all the selected keys on a track
            keylast = GetLastSelectedKey(op.GetFirstCTrack())
      
      
          
            if not keylast: offset = 0
            # the original cal moved everything # else: offset = key.GetTime().GetFrame(doc.GetFps())-overlap
            else: 
                print "OS1", offset
                offset = keylast.GetTime().GetFrame(doc.GetFps())-overlap
                print "OS2", offset
            # object namecheck # print op.GetName()
            if  i+1 < len(lst) : # +1 stops index going out of range ie more objects than listed
                op = lst[i+1]# ok to get next object in list
      
        return 
    #####################################
    def main() :
        import c4d
        from c4d import documents
        from c4d import gui
        
        c4d.CallCommand(1024314); # clear the python console
     
        # get a value form the user
        guival = gui.InputDialog("Enter a value < your max keyspan","10")
        print "Dialog Value =",guival
        overlap = int(guival)   
        doc = documents.GetActiveDocument()
        doc.StartUndo()
      
        lst = GetActiveObjects(doc) #get selected objects
      
        print "List Length = ", len(lst) 
        if len(lst)<=1:
            c4d.gui.MessageDialog("You need to select at least two objects") 
            return False #leave if not enough objects selected
     
        op = lst[0] #get fist active object
      
      
        keyfirst = GetFirstSelectedKey(op.GetFirstCTrack())
        keylast = GetLastSelectedKey(op.GetFirstCTrack())
        
      
        keyfirstval = keyfirst.GetTime().GetFrame(doc.GetFps())
        keylastval = keylast.GetTime().GetFrame(doc.GetFps())
        keyspanval = keylastval - keyfirstval
       
        print "Selected Keyspan 1st track = ", keyspanval
        print "Keytime of start key = ", keyfirstval
        print "Keytime of end key = ", keylastval
        
     
       
        if not keylast: offset = 0
        ##### else do the stagger
        else: Stagger(doc,op,lst,keylast,overlap) 
         
        doc.EndUndo()
      
    if __name__=='__main__':
        main()
      
    
    


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

    On 06/03/2011 at 08:05, xxxxxxxx wrote:

    Any feedback on programing 'form' would be appreciated.

    Think it would be useful to have a couple more transformations
    Stagger2 - enter total stagger length - x frames (rather than current overlap in frames)
    Accelerate - gradually space out over x frames
    Decelerate - reverse above
    Stack - thats essentially stagger with no overlap?



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

    On 06/03/2011 at 10:29, xxxxxxxx wrote:

    Well, works fine. If you want potential increament for eg. you need to calculate something with the offset value. ;-)



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

    On 06/03/2011 at 11:09, xxxxxxxx wrote:

    cheers Nux


Log in to reply