save previous position of an object

On 21/04/2016 at 09:11, xxxxxxxx wrote:

i want to save the position of many objects animated by an dynamic tag to calculate the velocity per frame for it

script tag is set to frame depending

  
import c4d
  
poly_arr_old = []
  
def main() :
  
    global poly_arr_old    
    
    poly = op.GetObject().GetDown()
    
    #poly_arr_new from objects
    poly_arr_new = []
    while poly:
        
        poly_arr_new.append(poly)        
        poly = poly.GetNext()
  
    if (len(poly_arr_old) == len(poly_arr_new)) :
        
        for i in range(0,len(poly_arr_new)) :
            #compare
            print (poly_arr_old[i].GetMg().off - poly_arr_new[i].GetMg().off).GetLength()
  
    
    # flush old list and create a COPY from poly_arr_new    
  
    poly_arr_old = []
    for item in poly_arr_new:
        poly_arr_old.append(item)
    
    
  
    print "#" * 64
    pass  #put in your code here
  

On 21/04/2016 at 10:40, xxxxxxxx wrote:

What is your question?

On 22/04/2016 at 01:30, xxxxxxxx wrote:

Hello,

as Nikals said, can you specify your question?

What exactly do you mean with "script tag"? I guess you mean a Python Tag? If you want to store data consistently across time you could store data for example in the BaseContainer of the tag itself.

Best wishes,
Sebastian

On 22/04/2016 at 04:06, xxxxxxxx wrote:

it seems to work fine but the previous and current frame data are still the same

import c4d
  
def main() :  
    bc = op.GetDataInstance()
    frame=doc.GetTime().GetFrame(doc.GetFps())
 
    poly = op.GetObject().GetDown()
    
    #poly_arr_new from objects
    
    poly_arr_new = []
    while poly:
        
        poly_arr_new.append(poly)        
        poly = poly.GetNext()
  
  
    if bc.GetData(frame+10000-1) != None:
        poly_arr_old = bc.GetData(frame+10000-1)
        
        for i in range(0,len(poly_arr_new)) :
            print poly_arr_old[i].GetMg().off
            print poly_arr_new[i].GetMg().off
  
    
    poly_arr_old = c4d.BaseContainer()
    i = 0
    for item in poly_arr_new:
        poly_arr_old.SetData(i,item)
        i +=1    
    
    bc.SetData(frame+10000,poly_arr_old)
    
    print "#" * 64
    pass  #put in your code here
  

On 22/04/2016 at 11:30, xxxxxxxx wrote:

I think you need to store the *positions* in the old and new arrays, not the objects : )  For example, instead of poly_arr_new.append(poly) you might have pos_array_new.append(poly.GetMg().off).