Custom menu and calling methods

I followed the cgcookie tutorial and modified it to add a custom sub menu in the Add menu - but it only calls mesh.primitive_cube_add. I tried to modify it to call a def function using the layout.operator function, but that didn’t work. How do I make a menu item call a function within the script?

you need to wrap your function with an operator class and register it.

See the Operator Simple template in blender text editor. The operator’s execute() method calls main(…), simply replace it. Change the operator idname and label, and use that in layout.operator(HERE)

Thanks for the reply.

class Make2x4x8(bpy.types.Operator):    
    bl_idname = "lumber.2x4x8"
    bl_label = "2x4x8"
    def execute(self, context):
        return {'FINISHED'}

class lumberMenu(bpy.types.Menu):
    bl_label = "Lumber Menu"
    bl_idname = "OBJECT_MT_select_LumberMenu"
    def draw(self, context):
        layout = self.layout
        layout.operator("lumber.2x4x8", text="2x4 8'")
        layout.operator("mesh.primitive_cube_add", text="2x4 10'")
        layout.operator("mesh.primitive_cube_add", text="2x6 8'")

The above works for the “2x4 10’” and 2x6 8’" - but not the “2x4 8’”

Solved - forgot to register the class. doh.