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 obj.keyframe_insert(data_path="hide") obj.keyframe_insert(data_path="hide_render") else: print ("Nope, not this object:") print (obj) #set invisible & non-renderable obj.hide = True obj.hide_render = True obj.keyframe_insert(data_path="hide") obj.keyframe_insert(data_path="hide_render")
(To try it parent a pile of objects to an empty, select one of them and run the script)