2
$\begingroup$

I'm trying to create a script that will batch-render a model with different values on an edge crease of a subdivision surface on a model.

My trouble is that while I can select the vertices in question, I can't find a way to change the parameter "Edge Crease" via script.

I am not sure it is even accessible somehow.

I attach the blender file for anyone feeling helpful! Blenderscript v2 for stackexchange.blend

$\endgroup$

1 Answer 1

3
$\begingroup$

You need to operate on the edges directly, but to get the changes this must be done in object mode.

import bpy
from bpy import data as D
from bpy import context as C
from mathutils import *
from math import *


bpy.ops.object.mode_set(mode='OBJECT')
bpy.ops.object.select_all(action='DESELECT')

obj = bpy.data.objects["Cube"]
obj.select_set(True)

vg1 = obj.vertex_groups['Crease']


bpy.ops.object.mode_set(mode='EDIT')

obj.vertex_groups.active = vg1
bpy.ops.object.vertex_group_select()
bpy.ops.object.mode_set(mode='OBJECT')

# iterate over all edges in the mesh data
for edge in obj.data.edges:
    # if the edge is selected
    if edge.select == True:
        # set its crease value to 0.2 in this case
        edge.crease = 0.2
$\endgroup$
5
  • 2
    $\begingroup$ You can read/edit this data in edit mode as well, problem being, that in edit mode the mesh state is copied as a BMesh, and on exiting the edit mode, the BMesh is saved back to the mesh state, overwriting all the changes done on the mesh (rather than BMesh). Inside BMesh you obtain crease data similarly to UV - first get the layer: CL = bm.edges.layers.crease.verify(), then use it on edges: creases = [e[CL] for e in bm.edges] $\endgroup$ Oct 1, 2022 at 15:53
  • $\begingroup$ Perfect Thank you! $\endgroup$
    – pataroulis
    Oct 1, 2022 at 16:41
  • $\begingroup$ @MarkusvonBroady is there some way to do edit creased without going to bmesh? $\endgroup$ Dec 5, 2022 at 13:06
  • 1
    $\begingroup$ @FamousSnake you wrote this question under an answer that does just that. $\endgroup$ Dec 5, 2022 at 15:17
  • $\begingroup$ @MarkusvonBroady if you test it in Blender - script does change edge crease (if you look it up in spreadsheet) but after you go to EDIT mode crease values goes back to zero. You can use simpler version of the script to reproduce it: for e in bpy.context.object.data.edges: e.crease = 1.0. Though just tested in Blender 3.4 alpha and it does work, so I guess it's some kind of a bug. $\endgroup$ Dec 5, 2022 at 16:42

You must log in to answer this question.

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