Need help wiht addon for 2.8

get error on bl idname

\what are the rules for bl Idname ?

thanks
happy bl

name appear in menu but not being run

I think you need to add the properties module may be
or something else will do test

this is first script I try in 2.8 and so many changes
not easy to get first one going

thanks
happy bl

sorry just saw you did not add the code for the class

I will add it and see if it begins to work

thanks
happy bl

added code for spiral

and after calling my add mat function
I had to correct the llnk ob line

but now I get an error on the active object

bpy.context.scene.objects.active = ob

any idea in 2.8 how to get the active object

thanks
happy bl

I think this.

bpy.context.view_layer.objects.active = ob

corrected that one
also corrected another one to select it

and now seems to work fine

nice will try to continue to add other class and hope it works well

thanks a lot for feedback
have a nice day
will continue tomorrow

happy bl

did some testing

I added another class for a new primitive
and the menu does not seem to see this new class

I then added the primitive template for a box
and did not work either

looks like menu cannot take more then one class of operator !
may be I did a mistake

did you test it with more then one class ?

thanks
happy bl

Yeah, multiple operators seems to work fine.

import bpy


class MENU_MT_MyCustom(bpy.types.Menu):      
    bl_label = "Parabola1"     
    bl_idname = "MENU_MT_my_custom_menu"
        
    def draw(self, context):
        layout = self.layout                             
        layout.operator(OBJECT_OT_operator_1.bl_idname, icon='MESH_CUBE')
        layout.operator(OBJECT_OT_operator_2.bl_idname, icon='MESH_UVSPHERE')           
        layout.operator(OBJECT_OT_operator_3.bl_idname, icon='MESH_CONE')
        layout.operator(OBJECT_OT_operator_4.bl_idname, icon='MESH_PLANE')
                        
def MyCustomMenuAdd(self, context):
    self.layout.menu(MENU_MT_MyCustom.bl_idname, icon='PLUGIN')


class OBJECT_OT_operator_1(bpy.types.Operator):
    """Operator 1"""
    bl_label = "Operator 1"
    bl_idname = "object.operator_1"
    bl_options = {'REGISTER', 'UNDO'}
                
    def execute(self, context):
        print("Add my operator code here")
        return {'FINISHED'}

class OBJECT_OT_operator_2(bpy.types.Operator):
    """Operator 2"""
    bl_label = "Operator 2"
    bl_idname = "object.operator_2"
    bl_options = {'REGISTER', 'UNDO'}
                
    def execute(self, context):
        print("Add my operator code here")
        return {'FINISHED'}

class OBJECT_OT_operator_3(bpy.types.Operator):
    """Operator 3"""
    bl_label = "Operator 3"
    bl_idname = "object.operator_3"
    bl_options = {'REGISTER', 'UNDO'}
                
    def execute(self, context):
        print("Add my operator code here")
        return {'FINISHED'}

class OBJECT_OT_operator_4(bpy.types.Operator):
    """Operator 4"""
    bl_label = "Operator 4"
    bl_idname = "object.operator_4"
    bl_options = {'REGISTER', 'UNDO'}
                
    def execute(self, context):
        print("Add my operator code here")
        return {'FINISHED'}
    
    
classes = (
    MENU_MT_MyCustom,
    OBJECT_OT_operator_1,
    OBJECT_OT_operator_2,
    OBJECT_OT_operator_3,
    OBJECT_OT_operator_4,            
)


def register():
    from bpy.utils import register_class
    for cls in classes:
        register_class(cls)    

    bpy.types.VIEW3D_MT_mesh_add.append(MyCustomMenuAdd)


def unregister():
    from bpy.utils import unregister_class
    for cls in reversed(classes):
        unregister_class(cls)
        
    bpy.types.VIEW3D_MT_mesh_add.remove(MyCustomMenuAdd)

    
if __name__ == "__main__":
    register()

has to do with rules for
class name and BL ID name

got this and not working

class OBJECT_OT_Hyperbo(bpy.types.Operator):

'''Add an Hyperbolic Paraboloid'''

bl_label    = "Hyperbolic Paraboloid"
bl_idname   = "object.hyperbo"
   bl_options = {'REGISTER', 'UNDO'}

menu is like this

	layout.operator( OBJECT_OT_Hyperbo.bl_idname , icon= 'MESH_CUBE')

note the box one is like this

class AddBox(bpy.types.Operator):

"""Add a simple box mesh"""

bl_idname = "mesh.primitive_box_add"
bl_label = "Add Box"
bl_options = {'REGISTER', 'UNDO'}

so something is wrong can you give me the trick here
can there be more then one way to call the operator or name it?
bl_idname does not have anything to do with class name in this case !

thanks
happy bl

got latest built today
and I tried to run the add mesh box
and it gives some error now !

don’t know if it is bug !

happy bl

Are you getting errors when running a operator, registering classes, trying it as addon, or running as script from text editor.

This is how classes needs named now, so the “AddBox” class you posted and the one below is wrong even though it seems to register fine.

The separator for each class is listed below:

* Header ->_HT_
* Menu ->_MT_
* Operator ->_OT_
* Panel ->_PT_
* UIList ->_UL_

Valid Examples:

* OBJECT_OT_fancy_tool
* SOME_HEADER_HT_my_header
* PANEL123_PT_myPanel *(lower case is preferred but mixed case is supported)* .

At the time of writing this, names that don't conform to this convention will produce a warning on startup.

If you run this from text editor it works fine. I’m not sure why your running into issues. My 2.8 build is from last night.

import bpy

class MENU_MT_MyCustom(bpy.types.Menu):      
    bl_label = "Parabola1"     
    bl_idname = "MENU_MT_my_custom_menu"
        
    def draw(self, context):
        layout = self.layout                             
        layout.operator(OBJECT_OT_Hyperbo.bl_idname, icon='MESH_CUBE')
        layout.operator(AddBox.bl_idname, icon='MESH_CUBE')           

                        
def MyCustomMenuAdd(self, context):
    self.layout.menu(MENU_MT_MyCustom.bl_idname, icon='PLUGIN')


class OBJECT_OT_Hyperbo(bpy.types.Operator):
    '''Add an Hyperbolic Paraboloid'''
    bl_label = "Hyperbolic Paraboloid"
    bl_idname = "object.hyperbo"
    bl_options = {'REGISTER', 'UNDO'}

    def execute(self, context):
        print("Add my operator code here")
        return {'FINISHED'}
    
class AddBox(bpy.types.Operator):
    """Add a simple box mesh"""
    bl_idname = "mesh.primitive_box_add"
    bl_label = "Add Box"
    bl_options = {'REGISTER', 'UNDO'}
        
    def execute(self, context):
        print("Add my operator code here")
        return {'FINISHED'}

    
classes = (
    MENU_MT_MyCustom,
    OBJECT_OT_Hyperbo,
    AddBox,            
)


def register():
    from bpy.utils import register_class
    for cls in classes:
        register_class(cls)    

    bpy.types.VIEW3D_MT_mesh_add.append(MyCustomMenuAdd)


def unregister():
    from bpy.utils import unregister_class
    for cls in reversed(classes):
        unregister_class(cls)
        
    bpy.types.VIEW3D_MT_mesh_add.remove(MyCustomMenuAdd)

    
if __name__ == "__main__":
    register()

If you’re just trying to add the primitive cube operator in the new menu. You need to do something like this.

layout.operator("mesh.primitive_cube_add", text="Add Box", icon='MESH_CUBE')

got new version today the 9
I run script from the text editor - so no install

I loaded up the add mesh box and still getting error
last week I tested it and it did work fine!

now for my script I run it also from text editor

I want to be able to add mesh I think
in the sense that when I add I want to be able to modify the properties for that object
so I guess this is adding mesh only
until you select another object then you loose the menu for that primitive

but in any case I added the classes name and call the operator
and I see only the first class the other don’t appear!

by the way is there a faster way to register all the classes auto
I mean I got scripts with 50 or 100 classes for adding primitive

here is file
I remove the addbox class
guess this one is not add mesh style - it just add a box and no properties

so you are saying if I want the properties for primitive then I need to use the mesh add thingny!

Add-Menu-Mesh2a.blend (113.3 KB)

thanks

I change the calls in menu
and now I can see the names for the different class

but got some error on linking ob to scene for the hyperpara class
and another error for first armchi too

with that the properties would appear in the 3D viewport if I remermber well

would be nice to be able to register all class with one function call!

thanks
happy bl