Post #2293: @minato, @MickHanks, yes, there is no Boolean P

📋 Metadata

🏷️ Tags

property-editor custom-properties advanced solved

  • Property Editor
  • Boolean Property
  • Python Scripting
  • Custom Icons

💬 Content

@minato, @MickHanks, yes, there is no Boolean Property for smooth/flat shading. But you can create your own:
Add a Boolean Property with this code:
Getter:

import bmesh; obj = C.edit_object or find_by(C.selected_objects, "type", 'MESH'); is_edit_mode = obj and obj.mode == 'EDIT'; me = obj and obj.data; bm = me and (bmesh.from_edit_mesh(me) if is_edit_mode else bmesh.new()); bm and not is_edit_mode and bm.from_mesh(me); bm and bm.faces.ensure_lookup_table(); f = me and bm.faces and (find_by(bm.faces, "select", True) if is_edit_mode else bm.faces[0]); ret = bool(f and f.smooth); bm and not is_edit_mode and bm.free(); return ret

Setter:

(bpy.ops.mesh.faces_shade_smooth() if value else bpy.ops.mesh.faces_shade_flat()) if C.mode == 'EDIT_MESH' else (bpy.ops.object.shade_smooth() if value else bpy.ops.object.shade_flat())

Or import this file and use imported Smooth-Flat Shading Property in Menu tab.

Should work in Object and Edit mode.


❤️ 1 likes


🔗 View on Blender Artists