Antonioya
(Antonioya)
October 9, 2015, 11:24am
1
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.
Antonioya
(Antonioya)
October 11, 2015, 8:00am
2
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')
Andrej
(Andrej)
December 5, 2022, 1:10pm
3
No idea why but it still happens - edge crease data that was set from python script disappears after going to EDIT mode. Not sure if it’s possible to fix without going to bmesh.
Simple script:
import bpy
for e in bpy.context.object.data.edges: e.crease = 1.0
My current solution is:
bm = bmesh.new()
bm.from_mesh(me)
crease_layer = bm.edges.layers.crease.verify()
for e in bm.edges:
e[crease_layer] = 1.0
bm.to_mesh(obj.data)
bm.free()
Andrej
(Andrej)
December 5, 2022, 4:30pm
4
Tested in 3.4 alpha (98670cfe8242) - the issue is gone, edge creases doesn’t disappear after going to EDIT mode. I guess it was a bug.
1 Like