Hi,
I’m making a simple script and trying to add it on to Blender. It works fine when run through the editor, but when I try to activate it as an addon, I get an error.
This is my script:
import bpy
bl_info = \
{
"name" : "Shadeless Setter",
"author" : "snuffysam",
"version" : (1, 0, 0),
"blender" : (2, 7, 8),
"location" : "Properties > Render > Shading",
"description" :
"Sets all materials to shadeless",
"warning" : "",
"wiki_url" : "",
"tracker_url" : "",
"category" : "Material",
}
class MaterialShadelessPanel(bpy.types.Panel) :
bl_space_type = "VIEW_3D"
bl_region_type = "TOOLS"
bl_context = "objectmode"
bl_category = "Tools"
bl_label = "Make Shadeless"
def draw(self, context) :
TheCol = self.layout.column(align = True)
TheCol.operator("mesh.make_shadeless", text = "Set All Shadeless")
TheCol.operator("mesh.make_shaded", text = "Set All Shaded")
#end draw
#end MaterialShadelessPanel
class MakeShadeless(bpy.types.Operator):
bl_idname = "mesh.make_shadeless"
bl_label = "Set All Shadeless"
bl_options = {"UNDO"}
def invoke(self, context, event):
for m in bpy.data.materials:
m.use_shadeless = True;
return {"FINISHED"}
#end invoke
#end MakeShadeless
class MakeShaded(bpy.types.Operator):
bl_idname = "mesh.make_shaded"
bl_label = "Set All Shaded"
bl_options = {"UNDO"}
def invoke(self, context, event):
for m in bpy.data.materials:
m.use_shadeless = False;
return {"FINISHED"}
#end invoke
#end MakeShaded
bpy.utils.register_class(MakeShaded)
bpy.utils.register_class(MakeShadeless)
bpy.utils.register_class(MaterialShadelessPanel)
And here is the error:
Traceback (most recent call last):
File "/private/var/folders/1w/wr7s_4s15dzbf2cn8gs87_rc0000gq/T/AppTranslocation/1519C7E6-7D56-4AE9-90DC-2B244B3945E6/d/blender.app/Contents/MacOS/../Resources/2.78/scripts/modules/addon_utils.py", line 349, in enable
mod.register()
AttributeError: module 'setAllShadeless' has no attribute 'register'
I am incredibly confused by this error message. “Has no attribute” implies that I called a function or variable that does not exist, right? But I don’t call a function or variable called “register” anywhere in the script. I call a function called “register_class”, but that should have nothing to do with this. And I certainly don’t call such a function with the line “mod.register()” as the error message seems to be claiming.
What’s going on? Am I completely misinterpreting the error message?