How to parent two object without selecting them manually in blender python scripting console? I want parent object which stored in variable like

Add a cube at the origin:


Create an empty object:


How to parent a to b?

a = bpy.context.object
b = bpy.context.object
const = b.constraints.new(type='CHILD_OF')
const.target = a

The simplest way to set a parent for an object is by accessing its parent property:

import bpy

# Create cube and reference the cube object
cube = bpy.context.object

# Create sphere empty and reference the empty object
empty = bpy.context.object

# Set the sphere empty as the parent of the cube object
cube.parent = empty
  • 2
    $\begingroup$ The drawback there is that the child will snap to the parents location, if they had been positioned first. You can select both, make the parent active and use bpy.ops.object.parent_set(type='OBJECT') to fill in the matrix to keep the child offset. $\endgroup$ – sambler Sep 6 '18 at 9:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.