1
$\begingroup$

I'm trying to set a Curve as a parent to objects using Python. My Curve's position is 0,0,0 at the World Origin. When I run the script below, the cubes get parented to the Curve and jump to a different location, yet their location values stay the same. Can someone please show me how to parent these objects to the Curve while keeping their world transforms?

Note: I noticed a more correct location when setting the Curve's dimensions to 3D.

Thank you!

Cubes being parented to a Curve with Python

import bpy
from mathutils import Vector

cube1 = bpy.data.objects["Cube"]
cube2 = bpy.data.objects["Cube.001"]
curve = bpy.data.objects["Circle.001"]
objects = [cube1,cube2]
for o in objects:
    o.parent = curve
    o.matrix_parent_inverse = curve.matrix_world.inverted()
$\endgroup$
1
  • 1
    $\begingroup$ it works if your circle is a mesh but not if it is a curve. why don't you convert it to mesh? or maybe report it as a bug $\endgroup$ Aug 27, 2022 at 2:17

1 Answer 1

0
$\begingroup$

The curve data's use_path needs to be disabled for the parenting to work with the curve's origin.

cube = bpy.data.objects["Cube"]
curve = bpy.data.objects["Circle"]
curve.data.use_path = False
cube.parent = curve
cube.matrix_parent_inverse = curve.matrix_world.inverted()
$\endgroup$
2
  • $\begingroup$ i see your ticket is resolved developer.blender.org/T100661 but how did you find out? $\endgroup$ Aug 27, 2022 at 4:06
  • 1
    $\begingroup$ @HarryMcKenzie I started ticking checkboxes in the Curve's properties and saw the relationship lines change with Path Animation. Thank you for the concern and the replies - very much appreciated! $\endgroup$ Aug 27, 2022 at 23:23

You must log in to answer this question.

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