Created
March 14, 2013 09:46
-
-
Save satishgoda/5160102 to your computer and use it in GitHub Desktop.
Updates to my original tutorial at https://sites.google.com/site/satishgoda/blender/blog/blender25xscriptinggettingtheworldcoordinates
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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