Post #3499: ![](https://blenderartists.org/user_avatar/blenderartists.org/kim_quyen/48/61154

📋 Metadata

  • Author: roaoao
  • Date: 2020-08-06 00:10:28
  • Type: answer
  • Quality Score: 9/10
  • Reply to: post_03495

🏷️ Tags

pie-menu custom scripting advanced solved

  • Pie Menu Editor
  • Custom Tab
  • Python Scripting
  • Command Tab
  • Custom Icons
  • Custom Labels

💬 Content

Kim_Quyen:

I have a Curve, I want to set up two types of Splines: Bezier / Poly assigned to a button. When i press the button, if the Splines are Bezier type will turn into Poly and vice versa.

Here is the code for Command tab:

sel_bezier_splines = [s for s in C.object.data.splines if [p for p in s.bezier_points if p.select_control_point]]; is_bezier = len(sel_bezier_splines) > 0; bpy.ops.curve.spline_type_set('INVOKE_DEFAULT', True, type='POLY' if is_bezier else 'BEZIER')

Or Custom tab with customizable icons and labels:

sel_bezier_splines = [s for s in C.object.data.splines if [p for p in s.bezier_points if p.select_control_point]]; is_bezier = len(sel_bezier_splines) > 0; L.operator("pme.exec", text="Bezier" if is_bezier else "Poly", icon='IPO_BEZIER' if is_bezier else 'IPO_CONSTANT').cmd = "bpy.ops.curve.spline_type_set('INVOKE_DEFAULT', True, type='%s')" % ('POLY' if is_bezier else 'BEZIER')

❤️ 3 likes


🔗 View on Blender Artists