Discussion:
[Bf-python] Python nodes API having issues with inheritance
Paul Kilgo
2013-05-20 17:52:46 UTC
Permalink
Hello

I am using the new Python API for node editor extensions to hopefully add a
my own volume renderer to Blender.

I'm struggling with finding a convenient way to add NodeSockets to a lot of
different nodes. I eventually settled with an inheritance hierarchy that
looks like this:

bpy.types.Node -> VolumeNode -> ScalarFieldNode -> SphereNode

I was defining a method ScalarFieldNode.init(self, context) to add some
sockets which will be common for scalar fields. However, it seems like
whenever I inherit from one of my nodes, the base class's init() method
does not carry over to the child class.

I poked around in bpy_types.py and found this perhaps relevant block of
code (in __new__ of RNAMetaNode):

init_base = classdict.get('init', None)
if init_base:
def init_node(self, context):
create_sockets(self)
init_base(self, context)
else:
def init_node(self, context):
create_sockets(self)
classdict['init'] = init_node

So I see that maybe I should be using input_templates and output_templates
to do what I am trying to do. I don't know Python that well so I don't know
if this is somehow breaking inheritance in the way I am trying to use it
(or even if I should use it) but I thought I would bring this to attention.

I've attached a simplified version of my script if it helps.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.blender.org/pipermail/bf-python/attachments/20130520/466f232c/attachment.htm
-------------- next part --------------
A non-text attachment was scrubbed...
Name: basic_example.py
Type: application/octet-stream
Size: 734 bytes
Desc: not available
Url : http://lists.blender.org/pipermail/bf-python/attachments/20130520/466f232c/attachment.obj
Dan Eicher
2013-05-21 05:59:51 UTC
Permalink
Hi,
From that (somewhat bizarre) snippet of metaclass voodoo it looks like you
should just be able to to call super().init() down through your chain of
subclasses and it'll eventually get to the wrapped call to create_sockets().

Or, if my metaclass knowledge is up to snuff, you'll end up making multiple
calls to create_sockets() and end up with a whole bunch of extra ones,
dunno really...

Dan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.blender.org/pipermail/bf-python/attachments/20130520/d96e98d0/attachment.htm
Paul Kilgo
2013-05-21 11:43:06 UTC
Permalink
Thank you for your reply!

So, sometime shortly after the 2.67 release, someone put forth a commit
which deleted all of the code in question. I downloaded yesterday's SVN
snapshot and inheritance did seem to work at least for the init() method,
so I guess maybe that bit of code was breaking the inheritance hierarchy. I
have a theory why but it doesn't really matter at this point.
Hi,
From that (somewhat bizarre) snippet of metaclass voodoo it looks like you
should just be able to to call super().init() down through your chain of
subclasses and it'll eventually get to the wrapped call to create_sockets().
Or, if my metaclass knowledge is up to snuff, you'll end up making
multiple calls to create_sockets() and end up with a whole bunch of extra
ones, dunno really...
Dan
_______________________________________________
Bf-python mailing list
Bf-python at blender.org
http://lists.blender.org/mailman/listinfo/bf-python
--
Paul Kilgo
paulkilgo at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.blender.org/pipermail/bf-python/attachments/20130521/cd0229b9/attachment.htm
Loading...