2
$\begingroup$

as MeshEdge.crease property has been removed in blender 4, how can I check and change the value of an edge crease ?
I used to do this to check edge crease value and set it to 1 if the value was over 0.1 in blender 3.x

for obj in bpy.context.selected_objects:
    if obj.type == "MESH":
        
        me = obj.data
        obj.select_set(True)                       
        bpy.context.view_layer.objects.active = obj

        for e in me.edges:
            
            if e.crease > 0.1:
                e.select = True
                print (obj.name, e.crease)
                e.crease = 1

Thanks

$\endgroup$

2 Answers 2

2
$\begingroup$

It seems to have moved to an attribute called "crease_edge", but the data only seems to be valid in Object Mode.

for obj in bpy.context.selected_objects:
    if obj.type == "MESH":
        
        me = obj.data
        obj.select_set(True)                       
        bpy.context.view_layer.objects.active = obj
        
        for e in me.attributes["crease_edge"].data:
      
            if e.value > 0.1:
                print (obj.name, e.value)
                e.value = 1
$\endgroup$
2
$\begingroup$

You can edit the attribute in edit mode but you have to use bmesh :

import bpy
import bmesh


for obj in bpy.context.selected_objects:
    if obj.type == "MESH":
        if obj.mode == "EDIT":        
            mesh = obj.data        
            attribute = mesh.attributes["crease_edge"]

            bm = bmesh.from_edit_mesh(mesh)
            crease_layer = bm.edges.layers.float.get(attribute.name)

            for edge in bm.edges:
                if edge[crease_layer] > 0.1:
                    edge[crease_layer] = 1

            bmesh.update_edit_mesh(mesh)
        else:
            print("See other answer")
$\endgroup$

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.