0
$\begingroup$

I have code that sets the bevel weight of selected edges in an object like this in Blender 3.3 LTS:

mesh = bpy.context.object.data
mesh.use_customdata_edge_bevel = True
for e in mesh.edges:
    e.bevel_weight = 0.0 if e.select else 1.0

According to the newest Blender 4.0 release notes, these edge weights are now set with the Attribute API. I've played around and searched for a while now and haven't been able to figure out how to set edge weight based on selected edges with the new attributes API. The documentation and examples of the attributes API seem fairly minimal at the moment.

What would the syntax be to accomplish the above goal (setting edge weight based on selection) in the Blender 4.0 attributes API (within an addon's Python code)?

$\endgroup$

2 Answers 2

1
$\begingroup$

Add a bevel and look in the attributes tab for the mesh enter image description here

You can access it by:
bpy.context.active_object.data.attributes['bevel_weight_edge'].data[1].value
or write to it with:
bpy.context.active_object.data.attributes['bevel_weight_edge'].data[1].value = 1.0
Where .data[1] is the edge index and .value is its value.

This must be done in OBJECT mode

Sorry, I'd write a longer answer but I just don't have time now :)

$\endgroup$
1
  • $\begingroup$ Thank you, this was helpful! $\endgroup$ Dec 3, 2023 at 6:24
0
$\begingroup$

Based on the helpful answer from Psyonic, I was able to implement this with a similarly simple bit of code to the original implementation. The missing puzzle piece I needed was that the attribute's data was referenced by edge index:

mesh = bpy.context.object.data
bevel_weight_attr = mesh.attributes.new("bevel_weight_edge", "FLOAT", "EDGE")
for idx, e in enumerate(mesh.edges):
    bevel_weight_attr.data[idx].value = 0.0 if e.select else 1.0
$\endgroup$
1
  • $\begingroup$ Yeah, that's the rest of it, but I'd check if it exists before blindly adding it $\endgroup$
    – Psyonic
    Dec 3, 2023 at 12:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .