Hey!
How can I add an object to the “Add” list. Example here:
I would like to make a custom object and the object to be in that menu. May be a simple question but I can’t find an answer anywhere. I know its possible because I’ve seen other addons that have this kind of features…
I just need to know how to execute my code when button is pressed in the menu. I alredy have the code for creating it written.
import bpy
def draw_item(self, context):
layout = self.layout
layout.operator("mesh.primitive_uv_sphere_add", text="My Operator")
def register():
bpy.types.VIEW3D_MT_mesh_add.append(draw_item)
def unregister():
bpy.types.VIEW3D_MT_mesh_add.remove(draw_item)
if __name__ == "__main__":
register()
I’m kind of new to python
this is my code:
import bpy
vertices = [(0, 0, 0),]
edges = []
faces = []
new_mesh = bpy.data.meshes.new('new_mesh')
new_mesh.from_pydata(vertices, edges, faces)
new_mesh.update()
new_object = bpy.data.objects.new('new_object', new_mesh)
new_collection = bpy.context.scene.collection
new_collection.objects.link(new_object)
Where should I add my code ? I’ve no idea what I’m doing…
import bpy
class MESH_OT_MyOperator(bpy.types.Operator):
"""Tooltip"""
bl_idname = "mesh.my_operator"
bl_label = "My Operator"
bl_options = {'REGISTER'}
def execute(self, context):
vertices = [(0, 0, 0),]
edges = []
faces = []
new_mesh = bpy.data.meshes.new('new_mesh')
new_mesh.from_pydata(vertices, edges, faces)
new_mesh.update()
new_object = bpy.data.objects.new('new_object', new_mesh)
new_collection = bpy.context.scene.collection
new_collection.objects.link(new_object)
return {'FINISHED'}
def draw_item(self, context):
layout = self.layout
layout.operator("mesh.my_operator", text="My Operator")
def register():
bpy.types.VIEW3D_MT_mesh_add.append(draw_item)
bpy.utils.register_class(MESH_OT_MyOperator)
def unregister():
bpy.types.VIEW3D_MT_mesh_add.remove(draw_item)
bpy.utils.unregister_class(MESH_OT_MyOperator)
if __name__ == "__main__":
register()
1 Like
Oooh!! Thanks man!
1 Like