Here is a script I did to automate autosmooth and set the degree. Pretty simple. It works in object mode great, however in edit mode it fails. What I do not understand is why. It does not matter if I am in edit or object mode when I use the regular buttons in Blenders UI.
class SetAutoSmooth(bpy.types.Operator):
bl_idname ="set.autosmooth"
bl_label ="Set Autosmooth"
def execute(self, context):
bpy.ops.object.shade_smooth()
bpy.context.object.data.use_auto_smooth = True
bpy.context.object.data.auto_smooth_angle = 0.523599
return {'FINISHED'}
Here is the error I get. It states that context is incorrect.
Traceback (most recent call last): File "C:\Users\info\Desktop\Coding.blend\class Pie.py", line 14, in execute File "C:\Users\info\Desktop\blender-2.76.0-git.d330162-AMD64\2.76\scripts\modules\bpy\ops.py", line 189, in call ret = op_call(self.idname_py(), None, kw) RuntimeError: Operator bpy.ops.object.shade_smooth.poll() failed, context is incorrect
location: :-1
