hey guys,
can someone help me with a toggle script for creasing an edge?
i found this command
bpy.ops.transform.edge_crease
but if i add (value=1) at the end nothing happens.
does anyone know why?
cheers christian
hey guys,
can someone help me with a toggle script for creasing an edge?
i found this command
bpy.ops.transform.edge_crease
but if i add (value=1) at the end nothing happens.
does anyone know why?
cheers christian
Reported:
https://developer.blender.org/T40467
You can avoid the operator and use:
import bpy
class SimpleOperator(bpy.types.Operator):
"""Tooltip"""
bl_idname = "object.simple_operator"
bl_label = "Simple Object Operator"
@classmethod
def poll(cls, context):
return context.active_object is not None
def execute(self, context):
ob = context.object
me = ob.data
mode = context.object.mode
bpy.ops.object.mode_set(mode='OBJECT')
for edge in me.edges:
if edge.select:
edge.crease = 1.0
bpy.ops.object.mode_set(mode=mode)
return {'FINISHED'}
def register():
bpy.utils.register_class(SimpleOperator)
def unregister():
bpy.utils.unregister_class(SimpleOperator)
if __name__ == "__main__":
register()
# test call
bpy.ops.object.simple_operator()
To avoid mode switches, use bmesh module:
import bpy
import bmesh
class SimpleOperator(bpy.types.Operator):
"""Tooltip"""
bl_idname = "object.simple_operator"
bl_label = "Simple Object Operator"
@classmethod
def poll(cls, context):
return context.active_object is not None
def execute(self, context):
ob = context.object
me = ob.data
bm = bmesh.from_edit_mesh(me)
cl = bm.edges.layers.crease.verify()
for edge in bm.edges:
if edge.select:
edge[cl] = 1.0
bmesh.update_edit_mesh(me, False, False)
return {'FINISHED'}
def register():
bpy.utils.register_class(SimpleOperator)
def unregister():
bpy.utils.unregister_class(SimpleOperator)
if __name__ == "__main__":
register()
# test call
bpy.ops.object.simple_operator()
awesome … many many thanks!!
would it be possible to make a toggle out of this btw so that i can put it to 1 shortcut instead of 2?
i just added one line to simultaneoulsy make the edge sharp as well as changed the name
bl_info = { "name": "hard_edges",
"location": "File/UserPrefs/Input Add new key in 3D View 'object.hard_edges'",
"description": "Hard Edges",
"category": "Mesh",
}
import bpy
class hard_edges(bpy.types.Operator):
"""hard_edges"""
bl_idname = "object.hard_edges"
bl_label = "hard_edges"
@classmethod
def poll(cls, context):
return context.active_object is not None
def execute(self, context):
ob = context.object
me = ob.data
mode = context.object.mode
bpy.ops.object.mode_set(mode='OBJECT')
for edge in me.edges:
if edge.select:
edge.crease = 1.0
bpy.ops.object.mode_set(mode=mode)
bpy.ops.mesh.mark_sharp(clear=False)
return {'FINISHED'}
def register():
bpy.utils.register_class(hard_edges)
def unregister():
bpy.utils.unregister_class(hard_edges)
if __name__ == "__main__":
register()
# test call
bpy.ops.object.hard_edges()
Sure you can toggle between states:
import bpy
import bmesh
class SimpleOperator(bpy.types.Operator):
"""Tooltip"""
bl_idname = "object.simple_operator"
bl_label = "Simple Object Operator"
@classmethod
def poll(cls, context):
return context.active_object is not None
def execute(self, context):
ob = context.object
me = ob.data
bm = bmesh.from_edit_mesh(me)
cl = bm.edges.layers.crease.verify()
for edge in bm.edges:
if edge.select and (edge[cl] == 0.0 or edge.smooth):
sharp = False
break
else:
sharp = True
for edge in bm.edges:
if edge.select:
edge[cl] = 0.0 if sharp else 1.0
edge.smooth = sharp
bmesh.update_edit_mesh(me, False, False)
return {'FINISHED'}
def register():
bpy.utils.register_class(SimpleOperator)
def unregister():
bpy.utils.unregister_class(SimpleOperator)
if __name__ == "__main__":
register()
# test call
bpy.ops.object.simple_operator()
works like a charm. many thanks again !
could you do me a favor and delete some messages in your inbox so i can send you a PM?
christian