When you run the script, the various properties in the script get set and you use them in your functions, this doesn't happen when you invoke the operator. An operator is invoked in a clean environment, you only get properties you setup in the operator. An addon is a python module and allows you to expand that to some degree as the script properties are actually module properties, but you still need to set the properties from the operator or the register() function, not the top level script steps.
From your operator's execute() method you should setup the properties you want to use based on the active selection at that time and not what may have been active at the time the script was run to register the operator. To do this, you should use the context parameter passed into the execute() method instead of using bpy.context, pass the context parameter from your operator to your functions when you call them.
As you mention - you have class main(), by creating an instance in your operator you aren't actually calling any of the methods listed in the class, so yes it should be a function not a class, unless you move the function calls into the class __init__() method or another method that you then call.
While you have worked out the steps you need to use, you just have to reorganise it so that it can be used within blenders operator context.
Does it want a bl_context tag set to 'NODE_EDITOR' or do I need to pass the context as the active material operator?
– Rug Aug 28 '17 at 21:23bpy.context. It is often the same but can be overridden. – sambler Aug 29 '17 at 04:59contextparameter passed to an operator is comparable tobpy.contextand should be used in it's place. It gives access to the current scene, active object, selected objects... Many times it will be the same asbpy.contextbut it can be altered for the duration of a script as described in the above link. – sambler Aug 31 '17 at 07:22Take for instance, my mat variable. That is a convenience variable that takes the active material using
bpy.context.active_object.active_material.name. Should I be usingcontextas the variable I am using when calling parameters instead ofmat? Or is context just something I throw in as a global, like
– Rug Aug 31 '17 at 17:44context = bpy.contextand then put it as a parameter for my functions?