Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorOmar Emara <mail@OmarEmara.dev>2021-02-20 19:05:13 +0300
committerOmar Emara <mail@OmarEmara.dev>2021-02-20 19:05:13 +0300
commitf2c0bbed1ce5270eee1332a02da02c1819bb230c (patch)
tree3bc309ba191cc1a4c81d3daa6e1b57fa987ef6a1 /doc
parent5dced2a0636a7f3db73be09139cf8abd952612e7 (diff)
Python: Add to_curve method to the object API
This patch adds a to_curve method to the Object ID. This method is analogous to the to_mesh method. The method can operate on curve and text objects. For text objects, the text is converted into a 3D Curve ID and that curve is returned. For curve objects, if apply_modifiers is true, the spline deform modifiers will be applied and a Curve ID with the result will be returned, otherwise a copy of the curve will be returned. The goal of this addition is to allow the developer to access the splines of text objects and to get the result of modifier applications which was otherwise not possible. Reviewed By: Brecht Differential Revision: https://developer.blender.org/D10354
Diffstat (limited to 'doc')
-rw-r--r--doc/python_api/examples/bpy.types.Depsgraph.7.py64
1 files changed, 64 insertions, 0 deletions
diff --git a/doc/python_api/examples/bpy.types.Depsgraph.7.py b/doc/python_api/examples/bpy.types.Depsgraph.7.py
new file mode 100644
index 00000000000..61209a6b9d2
--- /dev/null
+++ b/doc/python_api/examples/bpy.types.Depsgraph.7.py
@@ -0,0 +1,64 @@
+"""
+Dependency graph: Object.to_curve()
++++++++++++++++++++++++++++++++++++
+
+Function to get a curve from text and curve objects. It is typically used by exporters, render
+engines, and tools that need to access the curve representing the object.
+
+The function takes the evaluated dependency graph as a required parameter and optionally a boolean
+apply_modifiers which defaults to false. If apply_modifiers is true and the object is a curve object,
+the spline deform modifiers are applied on the control points. Note that constructive modifiers and
+modifiers that are not spline-enabled will not be applied. So modifiers like Array will not be applied
+and deform modifiers that have Apply On Spline disabled will not be applied.
+
+If the object is a text object. The text will be converted into a 3D curve and returned. Modifiers are
+never applied on text objects and apply_modifiers will be ignored. If the object is neither a curve nor
+a text object, an error will be reported.
+
+.. note:: The resulting curve is owned by the object. It can be freed by calling `object.to_curve_clear()`.
+.. note::
+ The resulting curve must be treated as temporary, and can not be referenced from objects in the main
+ database.
+"""
+import bpy
+
+
+class OBJECT_OT_object_to_curve(bpy.types.Operator):
+ """Convert selected object to curve and show number of splines"""
+ bl_label = "DEG Object to Curve"
+ bl_idname = "object.object_to_curve"
+
+ def execute(self, context):
+ # Access input original object.
+ obj = context.object
+ if obj is None:
+ self.report({'INFO'}, "No active object to convert to curve")
+ return {'CANCELLED'}
+ if obj.type not in {'CURVE', 'FONT'}:
+ self.report({'INFO'}, "Object can not be converted to curve")
+ return {'CANCELLED'}
+ depsgraph = context.evaluated_depsgraph_get()
+ # Invoke to_curve() without applying modifiers.
+ curve_without_modifiers = obj.to_curve(depsgraph)
+ self.report({'INFO'}, f"{len(curve_without_modifiers.splines)} splines in a new curve without modifiers.")
+ # Remove temporary curve.
+ obj.to_curve_clear()
+ # Invoke to_curve() with applying modifiers.
+ curve_with_modifiers = obj.to_curve(depsgraph, apply_modifiers = True)
+ self.report({'INFO'}, f"{len(curve_with_modifiers.splines)} splines in new curve with modifiers.")
+ # Remove temporary curve.
+ obj.to_curve_clear()
+ return {'FINISHED'}
+
+
+def register():
+ bpy.utils.register_class(OBJECT_OT_object_to_curve)
+
+
+def unregister():
+ bpy.utils.unregister_class(OBJECT_OT_object_to_curve)
+
+
+if __name__ == "__main__":
+ register()
+