[whatever is the answer, I don’t know, but a honor to have you around… Aware of your work since many years of an inclussion of that character(pepe?) in a Pc Actual (I think) magazine…]
Hey there !
It seems to me that you cannot set an item in that box by script. Last time I had a similar problem (setting pivot in window header) I had to code it myself (!).
Unless you are pointing specifically to some tutorial-like script, or whatever that needs GUI updates, you might be able to access shapekeys using Mesh.getKey(), but I couldn’t find any other hints on this.
It seems that Shapekey access is very scattered along the API. You can insertShapeKey() in Object module, but you cannot “getCurrentShapeKey” for instance…
Maybe some experienced coder could add some light on this.
I’m not completely certain if I understood you correctly, but I think you want to select an existing shapekey using python, which is pretty easy.
First some background information:
To access shapekeys via python you need to follow this chain:
Object --> Mesh --> Key (contains a list of KeyBlocks) --> KeyBlock (which is the actual shapekey)
The actual property to set is object.activeShape (malefico: this is the property that holds the current shapekey, so it is actually possible to get it and to set it).
import bpy from Blender import Draw def main(): sce = bpy.data.scenes.active ob = sce.objects.active if ob.type != "Mesh": return "Active object isn't a mesh" if not ob.data.key: return "Mesh doesn't have any shapekeys" blocks = ob.data.key.blocks blocknames = "" for b in blocks: blocknames+="|"+b.name choice = Draw.PupMenu("Select%t"+blocknames) if choice>0: ob.activeShape = choice return False error = main() if error: Draw.PupMenu("Error%t|"+error)
Oh that’s good to know Crouch ! thank you very much !
He he, long time ago The name of magazine was 3D total
Yep! 3d Total…the used to include readers 3d anims in the cd…
Pepeland: The ‘shape used as relative key’ should be in here, but as you can see it isn’t. There is some interesting information though:
A word on relative shape keys; relative shape keys are not actually stored as offsets to the base shape key (like you’d expect). Instead, each shape key stores an entire model (actually the state of the mesh vertices after exiting editmode with any given key active).
The additive offset for a shape key is calculated (when needed) by comparing the shape key with its base key, which is always the very first in the keyblock list.
Fortunately the second part of your request is possible. Just use object.Pinshape.
Here’s the example again:
import bpy from Blender import Draw def main(): sce = bpy.data.scenes.active ob = sce.objects.active if ob.type != "Mesh": return "Active object isn't a mesh" if not ob.data.key: return "Mesh doesn't have any shapekeys" blocks = ob.data.key.blocks blocknames = "" for b in blocks: blocknames+="|"+b.name choice = Draw.PupMenu("Select%t"+blocknames) if choice>0: ob.activeShape = choice ob.pinShape = True ob.makeDisplayList() return False error = main() if error: Draw.PupMenu("Error%t|"+error)
I added makeDisplayList() as well, to force the 3D-window to update to the selected shape.
About the ‘shape used as relative key’, the only solution I see is to bug a developer to add it. You didn’t hear that from me though :rolleyes:
Perfect again! so appreciated. In a couple of days you will see the reason of these questions
You make me curious, I’ll be on the lookout for it
check this thread :):