[Bf-python] pydrivers, 'self', and depgraph

Matt Ebb matt at mke3.net
Wed Aug 1 03:17:28 CEST 2007


Hi,

I've come across a bit of a problem with the 'self' keyword in pydrivers,
which is used to refer to the Blender object that the driver belongs to.

I have a situation where I have several characters, with individual objects
and armatures, but linked meshes. These characters are in groups, linked
into scene files using the group/proxy features.
i.e.
ShapeKey1 -> Mesh1 -> Ob1 -> Arma1
ShapeKey1 -> Mesh1 -> Ob2 -> Arma2
(not entirely accurate but you get the idea)

I have a shape key on that mesh that I'd like to control with a bone in the
armature, and I thought i should be able to do it with pydrivers. I wrote
the following huge pyDriver expression connected to my shape key (eg.
ShapeKey1), to find the armature (Arma1 or Arma2) which is modifying the
individual mesh objects, and using a bone to control the shape key:

self.modifiers[0][Blender.Modifier.Settings.OBJECT
].getPose().bones['HeadShrink'].size[1]

This works, when I scale the bone, the shapekey changes, but the problem is
it only works on one mesh object at a time. If I go to one of the other
armatures, its respective mesh/shape key doesn't change. If I then select
the second mesh object Ob2 and go to the shapekey pyDriver panel, and click
the little 'gear' icon twice to disable and re-enable the pydriver, it will
work fine, but then when I go back to the original character, it won't work.

I had a look at the code and saw this at BPY_pydriver_get_objects():
/* for depsgraph.c, runs py expr once to collect all refs. made
 * to objects (self refs. to the object that owns the py driver
 * are not allowed). */

I suspect that what is happening is that each pydriver can only have one
'self' object reference, and since in my case only one pydriver exists
(since there's only one ipo, on one shape key, on one mesh that's linked),
the self object gets evaluated only once.

Can anyone confirm or deny that this is how it works? I couldn't find any
documentation on it other than the commit log, which is reproduced (with
errors!) in the 2.44 release notes.

Is this a limitation of pydrivers? Or the depgraph? Anyone know of any
workarounds, or whether it's possible to fix? Thanks very much for your
help.

cheers,

Matt

PS. Originally in the pydriver I wrote just "Modifier.Settings.OBJECT",
which gave an error "NameError: name 'Modifier' is not defined". Antont
suggested I use Blender.Modifier.Settings.OBJECT which works fine. I think
it would be a good idea to have the Modifier module (and others?)
auto-imported for pydrivers.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.blender.org/pipermail/bf-python/attachments/20070801/44e3b420/attachment.html>


More information about the Bf-python mailing list