2
$\begingroup$

I have this method that I want to use to change the skin size of the skin modifier.

If I do this, everything works fine:

def make_uniform_width() -> None:
    bpy.ops.object.editmode_toggle()
    bpy.ops.mesh.select_all(action='SELECT')
    bpy.ops.transform.skin_resize(
        value=( self.properties.skin_size, self.properties.skin_size, self.properties.skin_size ),
    )
    bpy.ops.object.editmode_toggle()

I can just use: bpy.ops.mesh.select_all(action='SELECT') to change the value on all vertecies simultaniously.

But I want to select specific vertecies to do the skin_resize. So I thought this could work. But I have no access to the vertecies it seems.

def make_increase_width(self):
    bpy.ops.object.editmode_toggle()
    size = self.properties.skin_size
    for iteration in self._iterations:
        for vert in bpy.ops.object.vertecies:
            if vert.index in self._iterations[iteration]:
                vert.select = True
            else:
                vert.select = False

        size += self.properties.width_increase
        bpy.ops.transform.skin_resize(value=( size, size, size ))
    bpy.ops.object.editmode_toggle()

Is there a way to select specific vertecies from editmode?

EDIT: I tried this, but it's too slow te execute. Maybe I will have to look for another way to change the skin width.

def make_increase_width(self, vein_cluster_object):
    for iteration in self._iterations:
        vein_cluster_object.vertex_groups.new(name='growth-iteration-%i' % iteration)
    for iteration,group in zip(self._iterations,vein_cluster_object.vertex_groups):
        group.add(self._iterations[iteration], weight=1, type='REPLACE')
    bpy.ops.object.editmode_toggle()
    size = self.properties.skin_size
    for iteration in self._iterations:
        bpy.ops.mesh.select_all(action='SELECT')
        bpy.ops.object.vertex_group_deselect()
        bpy.ops.object.vertex_group_set_active(group='growth-iteration-%i' % iteration)
        bpy.ops.object.vertex_group_select()
        bpy.ops.transform.skin_resize(value=( size, size, size ))
        size += self.properties.width_increase
    bpy.ops.object.editmode_toggle()

I found it, I think. This should theoretically do the trick:

def make_increase_width(self):
    bpy.ops.object.editmode_toggle()
    size = self.properties.skin_size
    active_object = bpy.context.active_object
    for iteration in self._iterations:
        for vert in active_object.data.vertices:
            if vert.index in self._iterations[iteration]:
                vert.select = True
            else:
                vert.select = False
        bpy.ops.transform.skin_resize(value=( size, size, size ))
        size += self.properties.width_increase
        print(iteration, size)
    bpy.ops.object.editmode_toggle()

But it's very slow to execute. It seems having this line in the loop bpy.ops.transform.skin_resize(value=( size, size, size )) makes it too hard to do. It will select a maximum of 20 verts for about 60 iterations but somehow it will take far to long for it to run. I'm not sure how come.

$\endgroup$
9
  • $\begingroup$ Ah, bpy.ops.object.vertex_group_select() I will have to make vertex_groups I suspect $\endgroup$ Sep 17, 2019 at 18:27
  • 1
    $\begingroup$ Is it just a spelling problem? "vertecies" is "vertices" $\endgroup$
    – lemon
    Sep 18, 2019 at 8:15
  • $\begingroup$ That was very hopeful but no. or vert in bpy.ops.object.vertices: TypeError: 'BPyOpsSubModOp' object is not iterable $\endgroup$ Sep 18, 2019 at 9:00
  • 1
    $\begingroup$ vertices is an object property from context.object.data (not bpy.ops), depending on what the overall context is in your code. $\endgroup$
    – lemon
    Sep 18, 2019 at 9:08
  • $\begingroup$ Yes, I think I have found out that: active_object = bpy.context.active_object is giving me access to the vertecies. But vert.select = True is not actually selecting anything it seems. Hmm. ( I updated my question with the full code ) $\endgroup$ Sep 18, 2019 at 9:32

1 Answer 1

2
$\begingroup$

@lemon Was kind enough to help me find this answer:

def make_increase_width(self):
    size = self.properties.skin_size
    obj = bpy.context.active_object
    for iteration in self._iterations:
        size += self.properties.width_increase
    for iteration in self._iterations:
        for vert_index in self._iterations[iteration]:
            obj.data.skin_vertices[''].data[vert_index].radius = (size, size)
        size -= self.properties.width_increase

This is outside of edit mode, very fast and exactly what I needed.

$\endgroup$

You must log in to answer this question.

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