15

With Skin Modifier, we can "weight" a vertex (in Edit Mode) so that the resulting Skin mesh is bigger or smaller - similar to Curve objects which has "Scale Feather" adjustable.

Manually, we can hit Tab, go to Edit Mode, select Vertices, then CtrlA and drag.

However, I would like to be able to do this using Python. Does anyone know anything about it?

p2or
  • 15,860
  • 10
  • 83
  • 143
Jimmy Gunawan
  • 151
  • 1
  • 3

1 Answers1

15

Reading and writing these values from Python must happen in Object mode. I added a plane and deleted one vertex, added the skin modifier and decreased the radius of one vertex.

>>> obj = bpy.data.objects['Plane']
>>> for v in obj.data.skin_vertices[0].data:
...     print(v.radius[:])
...     
(0.25, 0.25)
(0.25, 0.25)
(0.08836718648672104, 0.08836718648672104)

Each element in skin_vertices[0].data has radius, use_loose, use_root to read and write. Radii can be any two element iterable (tuple, list).

import bpy

obj = bpy.data.objects['Plane']
for v in obj.data.skin_vertices[0].data:
    v.radius = 0.2, 1.2

I just realized that CtrlA lets you constrain the effect on radius per axis with ShiftX,Y.

Gwen
  • 11,636
  • 14
  • 68
  • 88
zeffii
  • 39,634
  • 9
  • 103
  • 186
  • 2
    Thanks so much for this answer @Zeffii! Right on solution. I was also surprised that we can constraint the effect either with X or Y axis. Only obvious when checking the radius value using Python, and it gives 2 values. Very interesting. I found this blog post that kind of talks a bit about the radius weight for skin vertices: http://michelanders.blogspot.com.au/p/creating-blender-26-python-add-on.html I will soon post this in my blog. – Blender Sushi Guy Jul 03 '13 at 01:21
  • 3
    @BlenderSushiGuy to let others know that this answer satisfies your question please log in with your other account and accept it. I recommend that you stop using two usernames, it's extra work in the long run. – zeffii Jul 03 '13 at 05:23
  • 1
    I first thought skin_vertices will contain data for each skin modifier (in case there are more than one), but it always has one element corresponding to first-added skin modifier! BTW great finding! – mg007 Aug 02 '13 at 18:36
  • note if you get an error, when trying to access or set skin weights, you need to first initialize at least one skin modifier either with code or using the UI – Gorgious Jun 21 '21 at 12:59