Can Python modify 2.40 shape key geometry?

The new shape keys in 2.40 are great, but…

From as far as I can see when using the new shape keys, you can specify a vertex group which the key uses and ignores everything else. That’s good because I can now easily modify the base geometry without affecting any of the keys and the updates can be immediately seen in object mode for each shape key.

However when I go into edit mode for any of the keys, the old mesh geometry is still there (but then when switching back to object mode the new geometry reappears again).

This can be annoying when working on a face that’s been modified after adding the shape keys, because you need to be able to view your shape key edits in relation to the actual face (not an original version of it). The only way I can do it at the moment is to keep editing a bit at a time while switching to object mode to see if it looks okay.

So my question is: Can I create a Python script that could update the geometry in a shape key so that it’s the same as the base shape (minus the specified vertex group)?

I think all that needs to be done is to translate the vertices of the shape key edit (except those within the specified vertex group) so they are the same as the base. But something tells me that it won’t be as simple as it sounds.

I have had a quick look into the API and it isn’t readily apparent, so a quick yes or no would be a great help before I spend way too many hours in Python.

Thanks in advance.

Edit: Oops, when I say face I mean a human face, not a quad face.

Yes I think that should be doable.

LetterRip

Hi,

Well, I spent all day today with Python trying to see if it can be done, and my conclusion is that it cannot (unless I’m doing something silly in the code).

I’ve included a link to simple blend file that has a real simple script that gets the key blocks and attempts to set all the verts of the ‘basis’ to (1,1,1). After you run the script (press Alt-p in the text window) you’ll see that the consiole displays the initial and updated values correctly, but for some reason they’re not being updated in the actual mesh (I am using NMesh.update() ).

Here’s a link to the blend file.

http://d.turboupload.com/d/270505/KeyTest.blend.html

In the file you’ll see that there is a base key and another key which has a vertex group associated to it.

The crazy thing is, I’ve tried simple vert mods and it all works right up until you add a mesh key - it’s almost as though adding a mesh key makes it all read-only.

I will admit my Python experience has only just begun today so I may have done something wrong. My C/C++ skills are much better, so I’m wondering if it may be quicker for me to delve into the actual source and add a hack?

Any comments or suggestions would be worshipped.

Hmmm I’m sorry I led you astray - I think i misread your question - you appear to be doing the same that I would do. It might indeed be faster for you to go to the source, just look at the python functions to find out what C functions you should look at.

LetterRip

I just read the official doc :
http://www.blender3d.org/documentation/240PythonDoc/Key.KeyBlock-class.html#data