0
$\begingroup$

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.

$\endgroup$

1 Answer 1

2
$\begingroup$

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.

$\endgroup$
2
  • $\begingroup$ That did it. Thank you really appreciate the help!!! $\endgroup$
    – Nburgess
    Commented Aug 14, 2019 at 16:12
  • 1
    $\begingroup$ It can be helpful to get into the habit of writing a print statement in every loop until you form an understanding of what exactly is in the list. It's better to have print statements you don't need than to be in the dark about what is causing an error. It's never safe to assume, and the computer always does exactly what you tell it to. Often, the hardest to squash bugs are in the part of the code you think is rock-solid! $\endgroup$ Commented Aug 14, 2019 at 16:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .