I have an add-on that creates new Materials and adds and connects all the required Nodes. The goal is to keep it all in code, no appending from .blends.
I want to replace a series of Nodes common to all the Materials with a shared Group node. I’ve got a working script that checks to see if the Group already exists, adds it if it does, and creates it if it doesn’t — about 80 lines of code.
If I add this block into each of the 23 individual material files, everything works fine. But I’d like to have those 80 lines of code in one file, and just call it as needed.
So, I have a file called
SpecularGroupNode.py that has the operator and script, and it starts with
"""Add/Get Specular Group Node"""
bl_label = "Specular Node Group"
bl_idname = 'node.specular_group_operator'
def execute(self, context):
__init__.py, I import it with
from .SpecularGroupNode import *
and I register the class
SpecularGroup, all good so far.
But I’m stuck on how to call the operator.
If it were a button in a panel, I would just write
row.operator("node.specular_group_operator", text="Specular Group")
and Bob’s your uncle, cool.
Best I’ve been able to gather is to call it from inside my Material file with
but this returns nothing, not even an error.
My brain’s a bit foggy after grinding on this add-on for the last few hours, but I presume I’ve got the wrong approach. For all my Googling and looking through other add-ons, I still haven’t found the “Ah-ha!” that clearly and specifically denotes the correct approach.
If anyone can offer the solution, I would be hugely grateful.
And/Or if you have the link to an online reference or tutorial on this very topic, that would be amazing.
Thanks in advance!