1
$\begingroup$

I'm building a custom menu using Serpens and python and I'm trying to recreate the same behavior than the menu we can find in the Item tab:

enter image description here

In order to do that I have this little code I'm using in Serpens

import bmesh

o  = bpy.context.object
d  = o.data
bm = bmesh.from_edit_mesh( d )

creaseLayer = bm.edges.layers.crease.verify()

selectedEdges = [ e for e in bm.edges if e.select ]
for e in selectedEdges: e[ creaseLayer ] = crease_weight

bmesh.update_edit_mesh( d )

This was made by looking at this previous post regarding a similar query from the past: Python code for Edge Data Bevel and Crease Weight?

However since Blender 4.0 it seems like the way to edit Creases changed and this code doesn't work anymore. What would be the best way to re-create this behavior now.

I've looked into bpy.ops.transform.edge_crease(value=newCreaseValue) and edge_creases_ensure but I'm not sure how to properly use them in my case.

Apologies for my lack and knowledge and thank you in advance!

Edit:

Solution found: We have to use this line to get the Crease layer, as Crease as been moved to a named float attribute:

creaseLayer = bm.edges.layers.float.get('crease_edge', None) if bpy.app.version >= (4,0,0) else bm.edges.layers.crease.active
$\endgroup$
6
  • 1
    $\begingroup$ I think replacing the verify() line by: creaseLayer = bm.edges.layers.float.verify() should do it. $\endgroup$
    – lemon
    Nov 19, 2023 at 10:38
  • $\begingroup$ Indeed! It fixes the issue! I'm not sure what does this mean. I'll do some research to understand it. Thank you so much! $\endgroup$ Nov 19, 2023 at 18:05
  • $\begingroup$ Not sure either... is float supposed to be crease systematically in this version? I don't know... $\endgroup$
    – lemon
    Nov 19, 2023 at 18:07
  • $\begingroup$ Actually it only worked the first time I tried it but somehow on other objects and after exporting the addon, it only turns the edges blue. It doesn't really change the Crease attribute. The float.verify creates a custom data layer. How can I propagate it back to the Crease attribute? Here are the changed I found regarding 4.0 wiki.blender.org/wiki/Reference/Release_Notes/4.0/Python_API Vertex and edge crease have been moved to generic attributes as well, with the names crease_vert and crease_edge. But I'm not sure what to do about this information.. $\endgroup$ Nov 19, 2023 at 19:23
  • 1
    $\begingroup$ Thanks lemon, here is the solution if anybody faces the same issue, with backward compatibility. creaseLayer = bm.edges.layers.float.get('crease_edge', None) if bpy.app.version >= (4,0,0) else bm.edges.layers.crease.active $\endgroup$ Nov 19, 2023 at 20:42

0

You must log in to answer this question.

Browse other questions tagged .