Crease value missing after enter in EDIT mode

I have a problem with the crease value when enter in EDIT mode.

I have the following code to create a plane with the creases set to 1.


import bpy


# Create object and mesh
mainmesh = bpy.data.meshes.new('Plane')
o = bpy.data.objects.new('Plane', mainmesh)
o.location = bpy.context.scene.cursor_location
bpy.context.scene.objects.link(o)


myvertex = [[-1.0, -1.0, 0.0], [1.0, -1.0, 0.0], [-1.0, 1.0, 0.0], [1.0, 1.0, 0.0]]
myfaces = [(0, 1, 3, 2)]


mainmesh.from_pydata(myvertex, [], myfaces)


# Edges Crease
mainmesh.edges[0].crease = 1.0
mainmesh.edges[1].crease = 1.0
mainmesh.edges[2].crease = 1.0
mainmesh.edges[3].crease = 1.0




o.select = True
bpy.context.scene.objects.active = o

After running the script, if you look the datablocks using the Outliner, I can see “1” in the crease value for each edge, but when enter in EDIT mode and back to OBJECT mode, the crease value is missing.

I’m missing some step in the creation of the mesh, but I don’t know what.

After some testing, I got the creases working, but I would like to avoid Bmesh, any idea?


import bpy
import bmesh


# Create object and mesh
mainmesh = bpy.data.meshes.new('Plane')
o = bpy.data.objects.new('Plane', mainmesh)
o.location = bpy.context.scene.cursor_location
bpy.context.scene.objects.link(o)


myvertex = [[-1.0, -1.0, 0.0], [1.0, -1.0, 0.0], [-1.0, 1.0, 0.0], [1.0, 1.0, 0.0]]
myfaces = [(0, 1, 3, 2)]


mainmesh.from_pydata(myvertex, [], myfaces)


o.select = True
bpy.context.scene.objects.active = o


bpy.ops.object.modifier_add(type='SUBSURF')
for mod in o.modifiers:
    if mod.type == 'SUBSURF':
        mod.levels = 2




bpy.ops.object.mode_set(mode='EDIT')
bm = bmesh.from_edit_mesh(o.data)
cl = bm.edges.layers.crease.verify()
bm.edges.ensure_lookup_table()


bm.edges[0][cl] = 1.0
bm.edges[1][cl] = 1.0
bm.edges[2][cl] = 1.0


bmesh.update_edit_mesh(o.data, False, False)
bpy.ops.object.mode_set(mode='OBJECT')