Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware 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

    Position Update

    PYTHON Development
    0
    20
    1.6k
    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
      Helper
      last edited by

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

      On 15/03/2012 at 11:37, xxxxxxxx wrote:

      Hi Lennart, Niklas,
      Its seems to me that it doesn't works... When I call "c4d.DrawViews" Cinema freeze.

      May be I wrote somenthing wrong...

      Here's my code:

      _

      _
        
      import c4d
      from c4d import documents
        
          
      def main() :
          fps     = doc.GetFps()
          frame = doc.GetTime().GetFrame(doc.GetFps())
          obj = op.GetObject()
          Distance = []
          
          for i in xrange (0, frame) :
              c4d.StatusSetBar(100*(i-0)/(frame-0))
              doc.SetTime(c4d.BaseTime(i,fps))
              c4d.DrawViews(c4d.DRAWFLAGS_ONLY_ACTIVE_VIEW|c4d.DRAWFLAGS_NO_THREAD|c4d.DRAWFLAGS_NO_REDUCTION|c4d.DRAWFLAGS_STATICBREAK)
              GPos = obj.GetAbsPos()
              c4d.GeSyncMessage(c4d.EVMSG_TIMECHANGED)
              
              Distance.append(GPos)
          doc.SetTime(c4d.BaseTime(frame,fps))
          c4d.EventAdd(c4d.EVENT_ANIMATE)
          c4d.StatusClear()   
          print Distance 
        
       _
      

      _

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

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

        On 15/03/2012 at 12:56, xxxxxxxx wrote:

        That example is for a Command setup, not runtime/expression.
        Typically to write to file and/or set keyframes etc.
        If you need to check object position at different frame(s) from current
        at runtime you might need to look into/use AnimateObject()

        Cheers
        Lennart

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

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

          On 15/03/2012 at 13:06, xxxxxxxx wrote:

          So you want to compute the distance an object traveled within a PythonTag? Why didn't you say so earlier? 😛
          I don't know why you want to store the distance between each frame in a list, anyway, just create a global-variable and store your data there. Iterating over the full timeline each frame is quite imperformant..

          import     c4d  
            
          data = dict( distance = 0,  
                     prevPos  = None )  
            
          def main() :  
            position = op.GetOrigin().GetAbsPos()  
              
            # Check for `None` explicit because `prevPos` could  
            # be `c4d.Vector(0)` which evaluates to `False`, too.  
            if data['prevPos'] is None:  
                pass  
            else:  
                data['distance'] += (position - data['prevPos']).GetLength()  
                  
            data['prevPos'] = position  
            print data['distance']
          

          -Niklas

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

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

            On 15/03/2012 at 13:31, xxxxxxxx wrote:

            @ Lennart: Thanks for your reply, I will look immediately
            @ Niklas: wow, you save my life 👍 Thank you!!!!

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

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

              On 15/03/2012 at 13:54, xxxxxxxx wrote:

              For a bit of trivia in the matter, using the following
              in a Py Generator (Optimize Cache Off) will animate
              an animated object per frame and generate a spline of the path
              and read the total length 🙂

              Cheers
              Lennart

                
              import c4d   
              from c4d.utils import SplineLengthData   
                
              def main() :   
                
                  fps           = doc.GetFps()   
                  doctime       = doc.GetTime()       
                  currentframe = doctime.GetFrame(fps)   
                  start        = doc.GetMinTime().GetFrame(fps)   
                  end           = doc.GetMaxTime().GetFrame(fps)   
                
                  pspline       = c4d.BaseObject(c4d.Ospline)   
                  pspline.ResizeObject(end,0)   
                     
                  obj = doc.SearchObject('Cube')# <- Animated Object   
                
                  for i in xrange(end) :   
                      doc.AnimateObject(obj,c4d.BaseTime(i, fps),c4d.ANIMATEFLAGS_0)   
                      pspline.SetPoint(i,obj.GetAbsPos())   
                        
                  pspline.Message(c4d.MSG_UPDATE)   
                
                  sld = SplineLengthData()   
                  sld.Init(pspline,0)   
                  tot = sld.GetLength()   
                  print tot   
                  sld.Free()   
                     
                  # Place obj back on track again   
                  doc.AnimateObject(obj,c4d.BaseTime(currentframe,fps),c4d.ANIMATEFLAGS_0)   
                  return pspline   
              
              1 Reply Last reply Reply Quote 0
              • H
                Helper
                last edited by

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

                On 15/03/2012 at 15:30, xxxxxxxx wrote:

                wow Lennart,  I'm touched 🙂
                Thank you so much

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

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

                  On 16/03/2012 at 04:21, xxxxxxxx wrote:

                  Hi Lennart,
                  just to know, why this code doesn't work fine now? The "Distance"list store alway the same vector again...

                  import c4d
                  #Welcome to the world of Python
                    
                  def main() :
                      fps     = doc.GetFps()
                      frame = doc.GetTime().GetFrame(doc.GetFps())
                      obj = op.GetObject()
                      Distance = []
                      for i in xrange (frame) :
                          doc.AnimateObject(obj,c4d.BaseTime(i, fps),c4d.ANIMATEFLAGS_0)
                          GPos =  obj.GetAbsPos()
                          Distance.append(GPos)
                      print Distance
                  

                  Cheers

                  Luther

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

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

                    On 16/03/2012 at 07:00, xxxxxxxx wrote:

                    Please note that you must not call update functions or change the document structure within the execution functions of objects/tags/materials/... this might lead to crashs. From the c4d.threading module:

                    For all threaded functions it's forbidden to:
                    > 1. Add an Event.
                    > 2. Make any changes to materials.
                    > 3. Change the structure of objects attached to the scene.
                    > 4. Change parameters of elements attached to the scene (allowed, but not recommended except for tags).
                    > 5. Call a Draw function.
                    > 6. Perform any GUI functionality (e.g. displaying messages, opening dialogs etc.).
                    > 7. During drawing to do any file operations. (During execution t's allowed.)
                    > 8. Create undos.
                    >

                    Cheers, Sebastian

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

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

                      On 19/03/2012 at 05:42, xxxxxxxx wrote:

                      Hi Sebastian,
                      thanks for your note. Any suggestion for my last post?

                      Cheers,

                      Luther

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

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

                        On 21/03/2012 at 15:09, xxxxxxxx wrote:

                        The AnimateObject() function needs an animated object as far as I know.
                        That is , key framed in some fashion.

                        To run it safer, regarding Sebastians notes, do the AnimateObject() function
                        on a clone of the object (it is not inserted into the doc).

                        Cheers
                        Lennart

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