Animating object visibility

Hi all,

I have written a script to import a whole bunch of sequentially numbered x3ds from file (actually its a modified version of this one). I have got everything down packed ready to animate but I cant for the life of me figure out the best way to make objects pop in and out of the render which is needed. I have tried bpy.ops.anim.keyframe_insert(type=‘Layer’, confirm_success=True) and moving to different layers in script but it wont work and also bpy.data.objects[geoname].keyframe_insert(“restrict_render”, True) but that also wont work and it just seems every time I find a “solution” blender has been updated since and changed or removed that functionality.
I can do it manually but with 10 sets of 200 x3ds this is not time feasible.
What I want is to import the x3d file and set it to render for only the right time

I am amatour but I would make that in this way.

import bpy

N=300
##number of objects you want animate
n=1
##index of first object you imported
##it is important when you have got camera plane or anything else in scene

f=0
bpy.context.scene.frame_set(f)
while(f<300):
bpy.data.objects[f+n].hide=True
bpy.data.objects[f+n].keyframe_insert(data_path=“hide”,index=-1,frame=(0))
f=f+1

f=0
while(f<300):
bpy.context.scene.frame_set(f)
bpy.data.objects[f+n].hide=True
bpy.data.objects[f+n].keyframe_insert(data_path=“hide”,index=-1,frame=(f-1))

bpy.data.objects[f+n].hide=False
bpy.data.objects[f+n].keyframe_insert(data_path="hide",index=-1,frame=(f-1))

bpy.data.objects[f+n].hide=True
bpy.data.objects[f+n].keyframe_insert(data_path="hide",index=-1,frame=(f+1))

print(f)  
f=f+1

I am amatour but I would make that in this way.

import bpy



N=300
##number of objects you want animate
n=1
##index of first object you imported
##it is important when you have got camera plane or anything else in scene


f=0
bpy.context.scene.frame_set(f)
while(f&lt;N):    
    bpy.data.objects[f+n].hide=True
    bpy.data.objects[f+n].keyframe_insert(data_path="hide",index=-1,frame=(0))
 
    print(f)  
    f=f+1
    
f=0
while(f&lt;N):
    bpy.context.scene.frame_set(f)
    bpy.data.objects[f+n].hide=True
    bpy.data.objects[f+n].keyframe_insert(data_path="hide",index=-1,frame=(f-1))
    
    bpy.data.objects[f+n].hide=False
    bpy.data.objects[f+n].keyframe_insert(data_path="hide",index=-1,frame=(f-1))
    
    bpy.data.objects[f+n].hide=True
    bpy.data.objects[f+n].keyframe_insert(data_path="hide",index=-1,frame=(f+1))
    
    print(f)  
    f=f+1

When you want to render one you must use hide_render instead.
And the source I get information http://blenderscripting.blogspot.com/2011/07/scripted-keyframing-of-hide-hide-render.html