3
$\begingroup$

I want to unparent an object.

I tried the following code

import bpy

selectedList = bpy.context.selected_objects
selectedList[0].removeParent()

However, the following error occurred and the parent could not be removed.

AttributeError: 'Object' object has no attribute 'removeParent'
Error: Python script fail, look in the console for now...

How can I make a selected object have no parent?

$\endgroup$
1

2 Answers 2

4
$\begingroup$

Solution 1:

Assume you have an object in python obj:

Try obj.parent = None

None is a keyword refer to nothing. You assign the object parent to nothing is equivalent to remove parent.

Solution 2:

Directly modified data in object without operator can lead to some problem. You can clear the parent in your blender, and in info panel you should see the python command: bpy.ops.object.parent_clear(type='CLEAR')

$\endgroup$
3
$\begingroup$

If you want the object to keep its position on the World coordinates, this is a more complete solution without using the Blender operators bpy.ops

world_loc = ob.matrix_world.to_translation()
ob.parent = None
ob.matrix_world.translation = world_loc
$\endgroup$

You must log in to answer this question.

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