Edge crease setting not working via script

Hi.
Why the script doesn’t work? The crease parameter takes the value 1 but then resets to 0 when switching to Edit mode.

import bpy

def crease_sharp_edges(obj):
    bpy.ops.object.mode_set(mode='OBJECT')

    for e in obj.data.edges:
        if e.use_edge_sharp:
            print (e.crease)
            e.crease = 1.0
            print (e.crease)
            #e.use_seam = True


crease_sharp_edges(bpy.context.active_object)

You can’t change mesh data in object mode, you need to be in Edit mode instead

The script doesn’t work in edit mode.
e.use_seam = True only works in Object mode, not in Edit mode.

Well, it doesn’t work in object mode either, because you can’t set the crease of an edge in object mode :man_shrugging: Why not set the crease in edit mode and then switch to object mode for use_seam?

I tested it in Edit mode, the script doesn’t mark creases this way.

import bpy

def crease_sharp_edges(obj):
bpy.ops.object.mode_set(mode=‘EDIT’)

for e in obj.data.edges:
    if e.use_edge_sharp:
        print (e.crease)
        e.crease = 1.0
        print (e.crease)
        #e.use_seam = True

crease_sharp_edges(bpy.context.active_object)

Are you just trying to turn sharp edges into creases? You’re going to need to use bmesh for this.

import bpy
import bmesh

obj = bpy.context.edit_object
me = obj.data

bm = bmesh.from_edit_mesh(me)
for e in bm.edges:
    if not e.smooth:
        e.crease = 1.0

bmesh.update_edit_mesh(me, False)