How do you assign vertex groups to mesh in python?

Hi all,

I’m having some trouble assigning vertex groups to Meshes. Here are the steps I’ve taken:

(1) Create a Blender.Mesh.Mesh object
(2) Link the Blender.Mesh.Mesh object to a Blender.Object object
(3) Link the Blender.Object.Object object to the current scene
(4) Calculate a bunch of vertex groups and call the function: [Blender.Mesh.Mesh.addVertGroup](file:///home/jingy/docs/blender2.4.2_py_doc/Mesh.Mesh-class.html#addVertGroup) to add the groups into the Blender.Mesh.Mesh object that I created in step (1). But I keep getting the error message:

[AttributeError: mesh must be linked to an object first…](file:///home/jingy/docs/blender2.4.2_py_doc/Mesh.Mesh-class.html#addVertGroup)

I’ve double and triple checked my code and the Blender.Mesh.Mesh object is indeed already linked to a Blender.Object.Object, so what am I doing wrong here? :confused:

Thanks for reading.

-D

That shouldent happen, there are reasons it might but without looking at your script a quick solution is to get the mesh again,

me = ob.getData(mesh=1)

This will result in a new PyObject but unlike NMesh you wont notice any slowdown.

if your interested in dealing with vertex groups differently I wrote some functions in BPyMesh so you could deal with vgroups as dictionaries.

most of the weightpaint_* tools use this utility functions alredy.

Thanks man!! I will check it out.

-D

Update: Yep, it works. Thanks a lot!