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.