# How to draw a slider button with a custom defined numeric value?

The following code generates this UI:

    row = layout.row()
row.prop(mesh, "use_auto_smooth", text="BreakEdge")
row.active = mesh.use_auto_smooth and not mesh.has_custom_normals
row.prop(mesh, "auto_smooth_angle", text="Angle")


This pretty much replicates the generic Blender Mesh Data panel.

What I would like to do is set the 180 by default to something like 30 which is more common for hard edge modeling than 180 to break an edge.

Would something like this even be possible overwriting the custom value I would like to begin with?

• I think the question title and the content of the question are quite different. Maybe it doesn't seem this way from the point of asking, but from a practical standpoint drawing just any slider which you can define yourself entirely using bpy.props vs setting the default of an existing mesh attribute are very different things. – zeffii Jan 5 '16 at 20:43

I don't know if it is possible to set the default auto_smooth_angle of each new Mesh object -- I think your reason for trying is legitimate. If it isn't possible there's an alternative you might be interested in.

Rather than changing a default property of a mesh's auto_smooth_angle a solution could be to offer an EnumProperty with some quick-pick options, in addition to the existing slider. The enum would update the slider when an option is selected, if you want to fine tune then you use the slider.

here the rough code:

import bpy
import math
from math import radians

class LayoutDemoPanel(bpy.types.Panel):
"""Creates a Panel in the scene context of the properties editor"""
bl_label = "Layout Demo"
bl_idname = "SCENE_PT_layout"
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "scene"

def draw(self, context):
layout = self.layout
scene = context.scene

obj = context.active_object
if obj and obj.data:
mesh = obj.data
else:
return

row = layout.row(align=True)
row.prop(mesh, "use_auto_smooth", text="BreakEdge")
row = layout.row(align=True)
row.active = mesh.use_auto_smooth and not mesh.has_custom_normals
row.prop(mesh, "claas_smooth_angle", expand=True)
row.prop(mesh, "auto_smooth_angle", text="")

def register():

obj = context.active_object
if obj and obj.data and obj.type=="MESH":
mesh = obj.data

bpy.types.Mesh.claas_smooth_angle = bpy.props.EnumProperty(
items=[(str(j), str(j), "", i) for i, j in enumerate([30, 45, 90])],
default="30",

bpy.utils.register_class(LayoutDemoPanel)

def unregister():
bpy.utils.unregister_class(LayoutDemoPanel)
del bpy.types.Mesh.claas_smooth_angle

if __name__ == "__main__":
register()


or

    row = layout.row(align=True)
row.prop(mesh, "use_auto_smooth", text="BreakEdge")
row = layout.row()
row.active = mesh.use_auto_smooth and not mesh.has_custom_normals
split = row.split(percentage=0.4)
row = split.row()
row.prop(mesh, "claas_smooth_angle", expand=True)
split = split.split()
row = split.row()
row.prop(mesh, "auto_smooth_angle", text="")


• I tried it out but nothing really changes when I press the button. Only the slider really has an influence. But I learned today that you can call bpy commands and there I could add a standard value - have to look into this as well. Thank yoiu for everything! – Claas Kuhnen Jan 5 '16 at 23:06
• it works here, maybe you copied it wrong. clicking the 30/45/90 enum, changes the auto_smooth_angle, and whenever it is changed (via code, or via ui) it sends its own update to change the way it gets displayed. – zeffii Jan 5 '16 at 23:27
• this won't affect the default of the auto_smooth_angle, incase that was perceived to be the case. This just provides an easy way to set that angle. – zeffii Jan 5 '16 at 23:32
• I must not have been clear in my English. What I mean no matter what button I press, the angle slider value is always valid. – Claas Kuhnen Jan 6 '16 at 0:07