Argument works in the python console but not in a loop?

by Nburgess   Last Updated August 14, 2019 05:15 AM

I can type

bpy.data.objects['hair02'].parent.select

into the the console and get a return but when it is in this loop it sends back an error. please see image below. I must be calling it improperly but not sure why. any help is appreciated.

Tags : python scripting


Answers 1


You're testing all of the objects that were selected when the script reached the line fbxs = [ ob for ob in bpy.context.selected_objects] One of these objects has no parent, so when the line ob.parent.select = True is run, Blender tries to find a parent and raises an error when it doesn't find one.

Try this instead:

if (ob.parent):
    ob.parent.select

or if that doesn't work for some reason, enclose it in a try:/except: block.

Joseph Brandenburg
Joseph Brandenburg
August 14, 2019 04:55 AM

Related Questions


Updated March 26, 2015 07:27 AM

Updated April 04, 2015 21:06 PM

Updated April 17, 2015 20:06 PM

Updated March 28, 2015 11:05 AM

Updated March 29, 2015 06:05 AM