This has me stumped.

import bpy

meshes = bpy.data.meshes
objects = bpy.data.objects
scene = bpy.context.scene

def new_mesh(name):
    verts = [(3, 3, -3), (3, -3, -3), (-3, -3, -3)]
    edges = [(0, 1),(1,2),(2,0)]
    mesh_data = meshes.new(name)
    mesh_data.from_pydata(verts, edges, [])
    return mesh_data

mesh = new_mesh('some_mesh')
obj = objects.new('example_obj', mesh)
obj.modifiers.new(type='SKIN', name='sv_skin')


# now switch the mesh to a new one.
obj.data = new_mesh('some_other_mesh')


This snippet demonstrates a problem I'm having. Once i've added a Skin Modifier to the object, and then change the mesh data by assigning a new mesh to .data, then skin_vertices seems to be empty.

Yes there are workarounds.

@stacker below points out that I can remove and add the modifier to make skin_vertices again. This is a solution I use already, but it results in a lot of extra code to make sure other modifiers stay in the right place. In viewer_skin.py (linked to) I am hardcoding the modifiers, but you should imagine that I don't want to make any assumptions about which modifiers are on that stack at all (except for the skin modifier)

I'm trying to not use bpy.ops.object.modifier_(move_up, move_down, add) because that requires an active object.

  • $\begingroup$ They will be created when you add a skin modifier: bpy.ops.object.modifier_add(type='SKIN') $\endgroup$ – stacker Jan 25 '15 at 13:25
  • $\begingroup$ wouldn't it work if you remove and add the skin-modifier after changing the mesh? $\endgroup$ – stacker Jan 26 '15 at 7:41
  • $\begingroup$ @stacker, yes! That's the workaround I use at moment. i'll further clarify the question to explain why that isn't optimal. $\endgroup$ – zeffii Jan 26 '15 at 8:45

When scripting updates to obj.data there currently (Jan 2016) does not seem to be a way to refresh data.skin_vertices without removing and adding the modifier.

For example if the "SKIN" modifier is named "sv_skin"

    # if modifier present, remove
    if 'sv_skin' in obj.modifiers:
        sk = obj.modifiers['sv_skin']

    # make new modifier and get reference to it.
    a = obj.modifiers.new(type='SKIN', name='sv_skin')

If you have a few other items on that object's modifier stack then there's a bit more bookkeeping to do.

Here's an example of a working scripted update to generate a lattice mesh with a skin modifier in Sverchok.

enter image description here

The code: https://gist.github.com/zeffii/e556ebcb33737a3fd58b

<-- includes the script, but does require Sverchok.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.