my for function doesn't work, help please

In my script I do a check of a list of objects to see if they are the currently selected object and to do something based on that but I can’t get it to work.

The scripts lists and checks all objects involved and find which one is the current selected but never finds which ones isn’t. It always reports the last object in the array as not the right one even if it is and nothing for any of the other objects.

I can’t see whats wrong with this script, can you?

import bpy
print ("---new run---")

#1 currently selected layer
current = bpy.context.object

#2 parent layer:
parent = bpy.context.object.parent

#3 all childs
childs = bpy.context.object.parent.children
print ("All Childs:")
print (childs)
print ("Currently selected:")
print (current)
#4 set visible & renderability to on or off.

for allachilds in childs:
    obj = allachilds    
    print ("now checking:")
    print (allachilds)
    if allachilds == current:
        print ("this is the right one!:")
        print (obj)
    #visible & renderable
    obj.hide = False
    obj.hide_render = False

    print ("Nope, not this object:")
    print (obj)
    #set invisible & non-renderable
    obj.hide = True
    obj.hide_render = True

(To try it parent a pile of objects to an empty, select one of them and run the script)

A case of bad intendation, sorry…

bpy.context.object is the active object

bpy.context.selected_editable_objects is a list of editable objects, which are currently selected, and the active object is usually part of it.

I really dunno what you are trying to do. Do you want to keyframe all sibling objects? With different visibility settings (mutually exclusive) for the active and the other selected objects?

Shouldn’t you just set a different value to be keyframed in that case?

hide_render = obj == current

and always keyframe?

I created a switch object script for cut-out animation (switching different image parts like hands, heads etc.) where I got the parts parented to an empty. I select the image object I want to be shown and run my script, this object is then set to visible and renderable and all other objects under that parent empty is hidden and non renderable. When I want to switch I select another image plane and run the script and this now becomes visible and all others hidden.

I now have a rudimentary version working.