How to make delay system in python for blender?

Hey guys, I want to make a delay system for my python script which makes the armature move locations based on what it receives and I saw that python in blender does it all in one go and I can’t seem to find a way to make it run one loop at a time. Does anyone know how to add a delay/timer into a python script that works with blender? :thinking:
Here is the code that I wish to delay: :point_down:

index = 0
while index < (limit + 1):
      bpy.ops.transform.translate(value=(listX[index], listY[index], listZ[index]), constraint_axis=(False, False, False), constraint_orientation='GLOBAL', mirror=False, proportional='DISABLED', proportional_edit_falloff='SMOOTH', proportional_size=1.61051)
      index += 1
      if index == limit:
          break

I hope I made this question clear this is my first time posting on this website :smiley:
By the way Is it wrong for me to use Cycle Render for armature movement or is it ok to use cycle renderer? - I have been using it for a few weeks now and It hasn’t cause many problems. :sweat_smile:
Oh and also the Blender Version I am using is 2.79 not 2.8

Update: I was able to solve after slaving away and thanks Secrop pointing in me the right direction it was simple as getting a keyframe gen to make a key frame with each iteration of the loop. Thanks Secrop! :smiley::smile:
Here is the code (Silly me) :sweat_smile::

# This part moves the LArm bone using the variables from the lists (listX, listY, listZ)
index = 0
frame = 5
while index < (limit + 1):
          bpy.ops.transform.translate(value=(listX[index], listY[index], listZ[index]), constraint_axis=(False, False, False), constraint_orientation='GLOBAL', mirror=False, proportional='DISABLED', proportional_edit_falloff='SMOOTH', proportional_size=1.61051)
          index += 1
          # Recirds the keyframe of the location of the armature moving in a plane (2D movement with a 3D model)
          bpy.ops.anim.keyframe_insert_menu(type='Location')
          # Sets the frame to always go up by two to make a smoother animation
          frame = frame + 2
          bpy.context.scene.frame_current = frame
          # Breaks the loop and also is the end of the program
          if index == limit:
            break

You might want to use modal operators and/or timers.

1 Like

Ok Secrop, I will Iook it up and tell you if that is what I want :slight_smile:

Ok Secrop, Sorry for the wait but I looked into the links you provided, I believe, although correct me if I’m wrong, that the model operators are not really what I need and the Application Timers are close to what I want however if there is anyway to make a primitive timer with or without the “def” function as I am still not as adept to how it works in python blender. But that is not to say that I wouldn’t acknowledge an example with the def method in it, it is just since I am trying to test it out in a basic form then fine tune it and make it more advanced later on. Hope this helped clarify some things :slightly_smiling_face::thinking::face_with_monocle:

I don’t know what you are trying to do exactly… (is it for the UI, for a game, or for an animation?):confused:
But afaik, you need to adapt your code to the ‘input -> operate data -> draw’ loop of blender. This means that if you want to have something that spans into multiple internal loops, you need to keep the operator being called in every loop until it’s finished… The operator will then receive the input events, and do something about them. In your case, if you want timed operations, you need to expecifically setup a timer in the invoke, and handle just the events from the timer, in the modal execution. The API manual has a bunch of examples, and some templates can be found in your blender folder (you can see them in the text editor menu->templates->python).

I want to this for an animation if it is possible. An example of what I am trying to achieve is basically something similar to a clock, every time it hits 60 seconds it resets at goes again and makes the minute value go up by one.:smile::safety_pin:
Also could you show me an example of how input works in blender because I am having trouble getting input to work for me in blender python, I tried to do some primitive input code where you just ask for a 0 and a 1 and print out something based on the input, but that doesn’t seem to work. :sweat::cold_sweat:

Then is just a matter of creating keyframes for your animation. You can insert keyframes to any property that can be animated… in the case of clock pointer, it would be the object’s rotation property.
You need to be consistent with your animation timings… a 24fps will require a keyframe every 24 frames to get 1 second per keyframe.