Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save satishgoda/5160102 to your computer and use it in GitHub Desktop.
Save satishgoda/5160102 to your computer and use it in GitHub Desktop.
# Create a bezier curve object
>>> bpy.ops.curve.primitive_bezier_curve_add()
{'FINISHED'}
# Get a reference to the curve object
>>> curve_object = bpy.context.active_object
# Print out its data path
>>> curve_object
bpy.data.objects['BezierCurve']
# Move the curve object by 1 unit on y-axis
>>> curve_object.location[1] = 1
# Get a reference to to the curve points
>>> curve_points = curve_object.data.splines[0].bezier_points
# Print the data path of the curve points
>>> curve_points
bpy.data.curves['BezierCurve.002'].splines[0].bezier_points
# Get the value of the world_matrix of the curve
>>> curve_object_world_matrix = curve_object.matrix_world
# Print the world matrix
>>> curve_object_world_matrix
Matrix(((1.0, 0.0, 0.0, 0.0),
(0.0, 1.0, 0.0, 1.0),
(0.0, 0.0, 1.0, 0.0),
(0.0, 0.0, 0.0, 1.0)))
# Print the object space coordinates of the curve points
>>> for curve_point in curve_points:
... print (curve_point.co)
...
<Vector (-1.0000, 0.0000, 0.0000)>
<Vector (1.0000, 0.0000, 0.0000)>
# Print the world space coordinates of the curve points
>>> for curve_point in curve_points:
... print ( curve_object_world_matrix * curve_point.co )
...
<Vector (-1.0000, 1.0000, 0.0000)>
<Vector (1.0000, 1.0000, 0.0000)>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment