So in this script for Csharpen I am getting an error after the first if for the bpy.ops.object.convert(target='MESH')
. I am not sure why that is since it was working fine before adding conditionals. Is there a reason why that is happening?
class sharpenOperator(bpy.types.Operator):
'''Sharpen With Modifiers and Bevelling'''
bl_idname = "csharpen.objects"
bl_label = "CSharpen"
bl_options = {'REGISTER', 'UNDO'}
ssharpangle = FloatProperty(name="SSharpening Angle", description="Set SSharp Angle", default= 30.0, min = 0.0, max = 180.0)
angle = FloatProperty(name="AutoSmooth Angle", description="Set AutoSmooth angle", default= 60.0, min = 0.0, max = 180.0)
bevelwidth = FloatProperty(name="Bevel Width Amount", description="Set Bevel Width", default= 0.0071, min = 0.002, max = .25)
applyAll = BoolProperty(default = True)
originalbevel = FloatProperty()
# ADD A DRAW FUNCTION TO DISPLAY PROPERTIES ON THE F6 MENU
def draw(self, context):
layout = self.layout
box = layout.box()
# DRAW YOUR PROPERTIES IN A BOX
box.prop( self, 'ssharpangle', text = "SsharpAngle" )
box.prop( self, 'angle', text = "SmoothingAngle" )
box.prop( self, 'bevelwidth', text = "BevelWidth")
box.prop( self, 'applyall', text = "ApplyAll")
def execute(self, context):
#convert angle
ob = bpy.context.selected_objects
angle = self.angle
originalbevel = self.originalbevel
ssharpangle = self.ssharpangle
angle = angle * (3.14159265359/180)
ssharpangle = ssharpangle * (3.14159265359/180)
bevelwidth = self.bevelwidth
#Sets the Bevel Width To The Orig Bevel Width
originalbevel = bpy.context.object.modifiers["Bevel"].width
if self.Applyall:
#remove modifiers no one would want applied in this instance
bpy.ops.object.modifier_remove(modifier="Bevel")
bpy.ops.object.modifier_remove(modifier="Solidify"
#convert to mesh for sanity
bpy.ops.object.convert(target='MESH')
#apply the scale to keep me sane
bpy.ops.object.transform_apply(location=False, rotation=False, scale=True)
#Start In Edit Mode
bpy.ops.object.mode_set(mode='EDIT')
#Unhide all The Geo!
bpy.ops.mesh.reveal()
#Clear SSharps Then Redo It
#bpy.ops.mesh.select_mode(use_extend=False, use_expand=False, type='EDGE')
#bpy.ops.mesh.select_all(action='DESELECT')
#bpy.ops.mesh.select_all(action='TOGGLE')
#AR suggested using -1s instead of Zeroes
#bpy.ops.transform.edge_bevelweight(value=-1)
#bpy.ops.mesh.mark_sharp(clear=True)
#bpy.ops.transform.edge_crease(value=-1)
#then do the csharp operator stuff.
bpy.ops.mesh.select_mode(use_extend=False, use_expand=False, type='EDGE')
bpy.ops.mesh.select_all(action='DESELECT')
#Sharpening now using the ssharpangle parameter.
bpy.ops.mesh.edges_select_sharp(sharpness=ssharpangle)
bpy.ops.transform.edge_bevelweight(value=1)
bpy.ops.transform.edge_crease(value=1)
bpy.ops.mesh.mark_sharp()
bpy.ops.object.editmode_toggle()
else:
#Start In Edit Mode
bpy.ops.object.mode_set(mode='EDIT')
#Unhide all The Geo!
bpy.ops.mesh.reveal()
#Clear SSharps Then Redo It
#bpy.ops.mesh.select_mode(use_extend=False, use_expand=False, type='EDGE')
#bpy.ops.mesh.select_all(action='DESELECT')
#bpy.ops.mesh.select_all(action='TOGGLE')
#AR suggested using -1s instead of Zeroes
#bpy.ops.transform.edge_bevelweight(value=-1)
#bpy.ops.mesh.mark_sharp(clear=True)
#bpy.ops.transform.edge_crease(value=-1)
#then do the csharp operator stuff.
bpy.ops.mesh.select_mode(use_extend=False, use_expand=False, type='EDGE')
bpy.ops.mesh.select_all(action='DESELECT')
#Sharpening now using the ssharpangle parameter.
bpy.ops.mesh.edges_select_sharp(sharpness=ssharpangle)
bpy.ops.transform.edge_bevelweight(value=1)
bpy.ops.transform.edge_crease(value=1)
bpy.ops.mesh.mark_sharp()
bpy.ops.object.editmode_toggle()
#keep the old here for now
bpy.ops.object.modifier_add(type='BEVEL')
bpy.context.object.modifiers["Bevel"].use_clamp_overlap = False
bpy.context.object.modifiers["Bevel"].show_in_editmode = False
bpy.context.object.modifiers["Bevel"].width = 0.0071
bpy.context.object.modifiers["Bevel"].segments = 3
bpy.context.object.modifiers["Bevel"].profile = 0.70
bpy.context.object.modifiers["Bevel"].limit_method = 'WEIGHT'
#Sets Bevel To Bevel Width needs IF
bpy.context.object.modifiers["Bevel"].width = bevelwidth
bpy.context.object.data.use_auto_smooth = True
#now sets angle to Var angle.
bpy.context.object.data.auto_smooth_angle = angle
bpy.ops.object.shade_smooth()
return {'FINISHED'}