1
$\begingroup$

i saw many custom nodetree without registering the poll function class, i am wondering why and if this needed in some cases

this exemple:

class my_TreeNode:
@classmethod
def poll(cls, ntree):
    return ntree.bl_idname == 'my_TreeType'

as all custom nodes, related to this tree, need to get access to this class (of course), why it is not registered? ... especially if the nodes are located into other python files.

EDIT: by the way, when i put this content into a separate file, and do import it in my init file, i have an error:

name 'my_TreeNode' is not defined

is this class need to stay in my init file?

$\endgroup$
4
  • $\begingroup$ Looks like this is a Python question and unrelated to Blender? $\endgroup$ Commented Nov 9, 2022 at 20:35
  • $\begingroup$ this is about Blender custom nodetree addon coding (of course blender python BPY). $\endgroup$ Commented Nov 9, 2022 at 22:40
  • $\begingroup$ I'm not 100% sure, but it looks to me it's a Python problem. Perhaps you don't realize that it is: defining a class the way you show in the code snippet is not Blender-specific. "Why is my custom class not registered?" is also unclear; if I knew what you mean I probably would answer even though this seems off-topic to the BSE. $\endgroup$ Commented Nov 9, 2022 at 22:52
  • $\begingroup$ hi markus, in the blender template, related to this post, this class is not registered. and i don´t undetstand why, as i always register all my class when writing addon. i know this class refers to a specific area of nodetree (ntree), and for this it should be a reason to be available... and registered... am i wrong here ? as it is not registered, when i move it into a separate file, i got this error as it is not defined... can you explain me if you know about, that would be very great, thank you $\endgroup$ Commented Nov 10, 2022 at 23:17

1 Answer 1

3
$\begingroup$

I have answered your other question on this subject.

This class is not registered because it is a Mix-in class.

From the custom nodes template in Blender:

# Mix-in class for all custom nodes in this tree type.
# Defines a poll function to enable instantiation.
class MyCustomTreeNode:
    @classmethod
    def poll(cls, ntree):
        return ntree.bl_idname == 'CustomTreeType'


# Derived from the Mix-in class and Node base type.
class MyCustomNode(MyCustomTreeNode, Node):
   ...

Basically, the MyCustomNode class must be a subclass of MyCustomTreeNode and Node. In fact all the custom nodes you want to do must inherit these two classes.

If you move the Mix-in class to another file, you must import it from there before you use it.

It does not need to be registered because it is a Python class, so all nodes that inherit from it use the same poll method (it is a class method, so it exists once for all instances of the class).

Hope this helps,
David

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .