Adding object with only one single vertice at the 3d cursor

Hey guys,

I am starting to learn python. First of all I am trying to add an object, that has only one single vertice in the center. I have loaded the “add mesh” template and tried to edit it, so only one vertice will be added. What did I do wrong?

Thank you for the help :slight_smile:

Here is the code:

bl_info = {
“name”: “Single Vertice”,
“author”: “meierdesigns”,
“version”: (1, 0),
“blender”: (2, 80, 0),
“location”: “View3D > Add > Mesh > New Object”,
“description”: “Adds a new single vertice”,
“warning”: “”,
“wiki_url”: “”,
“category”: “Add Mesh”,
}

import bpy
from bpy.types import Operator
from bpy.props import FloatVectorProperty
from bpy_extras.object_utils import AddObjectHelper, object_data_add
from mathutils import Vector

def add_object(self, context):
scale_x = self.scale.x
scale_y = self.scale.y

vertice = [(0 , 0 , 0)]


mesh = bpy.data.meshes.new(name="New Object Mesh")
mesh.from_pydata(verts, edges, faces)
# useful for development when the mesh may be invalid.
# mesh.validate(verbose=True)
object_data_add(context, mesh, operator=self)

class OBJECT_OT_add_object(Operator, AddObjectHelper):
“”“Create a new Mesh Object”""
bl_idname = “mesh.add_object”
bl_label = “Add Mesh Object”
bl_options = {‘REGISTER’, ‘UNDO’}

scale: FloatVectorProperty(
    name="scale",
    default=(1.0, 1.0, 1.0),
    subtype='TRANSLATION',
    description="scaling",
)

def execute(self, context):

    add_object(self, context)

    return {'FINISHED'}

Registration

def add_object_button(self, context):
self.layout.operator(
OBJECT_OT_add_object.bl_idname,
text=“Single Vertice”,
icon=‘PLUGIN’)

This allows you to right click on a button and link to documentation

def add_object_manual_map():
url_manual_prefix = “https://docs.blender.org/manual/en/latest/
url_manual_mapping = (
(“bpy.ops.mesh.add_object”, “scene_layout/object/types.html”),
)
return url_manual_prefix, url_manual_mapping

def register():
bpy.utils.register_class(OBJECT_OT_add_object)
bpy.utils.register_manual_map(add_object_manual_map)
bpy.types.VIEW3D_MT_mesh_add.append(add_object_button)

def unregister():
bpy.utils.unregister_class(OBJECT_OT_add_object)
bpy.utils.unregister_manual_map(add_object_manual_map)
bpy.types.VIEW3D_MT_mesh_add.remove(add_object_button)

if name == “main”:
register()

You have to be more specific, what’s not working!


This is the error:

    verts = [(0,0,0)]

    edges = []
    faces = []

    mesh = bpy.data.meshes.new(name="New Object Mesh")
    mesh.from_pydata(verts, edges, faces)

mesh.from_pydata(verts, edges, faces) expects a variable named verts not vertice and empty lists for edges and faces.