[Bf-committers] registering 'dynamically generated' ops?

Bassam Kurdali bkurdali at freefactory.org
Mon Sep 13 17:38:47 CEST 2010


Hi all
  Since Martin's commit for I believe metaclassing, registering ops
became obsolete, raising an AttributeError, instead, ops created (via
python) are automatically registered- very nice!
  However I have one script (the clone of 2.4x's copy menu):
https://svn.blender.org/svnroot/bf-extensions/contrib/py/scripts/addons/space_view3d_copy_attributes.py

 This script dynamically builds the ops, so that it is easy to extend
just by writing a function that copies something from one object (or
bone) to another, the rest (looping over all the selected bones, making
the operators to be called from the menu) is handled more or less
automatically by the script.

 Before Martin's commit, I had a small loop in the register function
that would go over the list of generated ops and register them one by
one. After the commit, this raised an attribute error as expected. So I
removed the registration of the ops, and the script runs without error,
However, when I try to execute any operator from the menu, I get an
error on the console, indicating that my operator call is invalid - it
seems I need to register those operators explicitly after all.

 I found a workaround that worked for me, this was making a loop to
unregister all the dynamically generated ops, and then to register them
again. This works fine on Linux, but the unregistering step failed on
meta-androtico's Windows 7 machine! so finally I have wrapped things in
a try - except, where:
first we try to just register the ops (shouldn't be needed but is) -
this works on windows 7,
second if we get an AttributeError exception, we unregister the ops, and
then register them again ( this works on Linux )

Clearly this is not ideal, I think we should find a better way, so my
question is: 
Am I doing something wrong? is there a 'right way' to do this for
dynamically generated operators? and finally, why is the behavior OS
dependent?

Cheers
Bassam
 



More information about the Bf-committers mailing list