loop works only for 4 frames any idea why? I'm trying to use scripting to create jumpy cone for fire purpose, and the loop works only for 4 frames, any idea why? Thanks in advance 

import bpy
import random

for object in bpy.data.objects:    

    bpy.ops.object.select_all(action = 'DESELECT')    

    string1 = object.name

    for o in string1:

    if (string1.find("Cone",0)!=(-1)):

        object.select = True

        c = 2

        a = random.randrange(10,30)

        b = random.randrange(3,6)

        a /= b       

        # make each object that string1 find, "ACTIVE"
        bpy.context.scene.objects.active = bpy.data.objects[object.name]

        object.scale.z = a

        bpy.context.scene.frame_current = c

        bpy.ops.anim.keyframe_insert_menu(type='Scaling')

        c += 1
Can do this without operators.  I've set script to run on all objects in scene with a name starting with "Cone".

A common blender technique is to select an object and simply use

cone = context.active_object


Here is test code that adds a random z scale for cone on each frame from scene.frame_start to scene.end_frame.

import bpy
from random import randrange
from bpy import context
scene = context.scene
cones = [o for o in scene.objects if o.name.startswith("Cone")]

for cone in cones:
    c = scene.frame_start
    while c &lt;= scene.frame_end:      
        a = randrange(10,30)
        b = randrange(3,6)

        cone.scale.z = a / b
        cone.keyframe_insert("scale", index=2, frame=c)
        c += 1