Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    save previous position of an object

    Scheduled Pinned Locked Moved PYTHON Development
    5 Posts 0 Posters 444 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H Offline
      Helper
      last edited by

      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
        
      
      
      1 Reply Last reply Reply Quote 0
      • H Offline
        Helper
        last edited by

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

        What is your question?

        1 Reply Last reply Reply Quote 0
        • H Offline
          Helper
          last edited by

          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

          1 Reply Last reply Reply Quote 0
          • H Offline
            Helper
            last edited by

            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
              
            
            
            1 Reply Last reply Reply Quote 0
            • H Offline
              Helper
              last edited by

              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).

              1 Reply Last reply Reply Quote 0
              • First post
                Last post