user: Show practical ways to work with Object Parent in a Blender add-on or script – include code.

assistant: *Object Parent* is the most general form of parenting that Blender supports.
It will take selected objects and make the [active object](../selecting.html#object-active)
the parent object of all the selected objects. Each child object will inherit
the transformations of the parent. The parent object can be of any type.

If the object has a preexisting parent, that is cleared first.
This moves the object to its own location, rotation and scale,
without its parent’s influence.

There are three operators that allow you to set an object parent. They differ in
the way they compute the [Parent Inverse matrix](#parent-inverse-matrix)
and the local [Transform](../../../glossary/index.html#term-Transform) of the object.

### Example: Object Parent (Keep Transform)

*Object Parent* with *Keep Transform* will keep any previous transformations applied to them from
the previous parent object.

Assume that we have a scene consisting of three objects, those being two empty objects named “EmptyA”
and “EmptyB”, and a Monkey object. Fig. [Scene with no parenting.](#fig-view3d-parent-scene-no) shows the three objects with
no parenting relationships active on them.

[image reference removed]

Scene with no parenting.

If you select the Monkey object by `LMB` click and then `Shift`-`LMB`
click “EmptyA” object and press `Ctrl`-`P` and finally select *Object*
from the *Set Parent To* pop-up menu.
This will result in “EmptyA” object being the parent object of the Monkey object.
With only “EmptyA” selected rotating/scaling/moving it will result in
the Monkey object being altered respectively.

Scale the “EmptyA” object, so that the Monkey becomes smaller and moves to the left a little.

[image reference removed]

The monkey is the child object of “EmptyA”.

If you select only the Monkey object by `LMB` click and then `Shift`-`LMB`
click “EmptyB” object and press `Ctrl`-`P` and select *Object* from
the *Set Parent To* pop-up menu.
This will result in “EmptyB” object being the parent object of the Monkey object.
Notice that when you change the parent of the Monkey the scale of the Monkey changed.

[image reference removed]

The monkey is the child object of “EmptyB”.

This happens because the Monkey object never had its scale altered directly,
the change came about because it was the child of “EmptyA” which had its scale altered.
Changing the Monkey’s parent to “EmptyB” resulted in those indirect changes in scale being
removed, because “EmptyB” has not had its scale altered.

This is often the required behavior, but it is also sometimes useful that
if you change your parent object that the child object keep any previous transformations
it got from the old parent object; If instead when changing the parent object of the Monkey
from “EmptyA” to “EmptyB” we had chosen parenting type *Object* and enable *Keep Transform*,
the Monkey would keep its scale information it obtained from the old parent “EmptyA”
when it is assigned to the new parent “EmptyB”.

[image reference removed]

The Object parent with *Keep Transform*.

If you want to follow along with the above description here is the blend-file:

[File:Parent_-_Object_(Keep_Transform)_(Demo_File).blend](https://archive.blender.org/wiki/2015/index.php/File:Parent_-_Object_(Keep_Transform)_(Demo_File).blend/).