forked from vvoovv/blender-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vertex_object_at_cursor.py
55 lines (46 loc) · 1.87 KB
/
vertex_object_at_cursor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
bl_info = {
"name": "One-vertex mesh object at the cursor location",
"author": "Vladimir Elistratov <[email protected]>",
"version": (1, 0, 0),
"blender": (2, 7, 8),
"location": "View 3D > Object Mode > Tool Shelf",
"description": "Create one-vertex mesh object at the cursor location",
"warning": "",
"wiki_url": "https://github.com/vvoovv/blender-tools/wiki/One-vertex-mesh-object-at-the-cursor-location",
"tracker_url": "https://github.com/vvoovv/blender-tools/issues",
"support": "COMMUNITY",
"category": "3D View",
}
import bpy
class PlaceVertexAtCursorPanel(bpy.types.Panel):
bl_space_type = "VIEW_3D"
bl_region_type = "TOOLS"
bl_context = "objectmode"
bl_label = "New Object"
def draw(self, context):
c = self.layout.column()
c.operator("object.vertex_object_at_cursor")
class PlaceVertexAtCursor(bpy.types.Operator):
bl_idname = "object.vertex_object_at_cursor"
bl_label = "One-vertex object at the cursor"
bl_options = {"UNDO"}
bl_description = "Create one-vertex mesh object at the cursor location"
def execute(self, context):
# setting active object if there is no active object
if not context.scene.objects.active:
context.scene.objects.active = context.scene.objects[0]
bpy.ops.object.mode_set(mode="OBJECT")
mesh = bpy.data.meshes.new("")
mesh.from_pydata([context.scene.cursor_location], [], [])
mesh.update()
obj = bpy.data.objects.new("", mesh)
context.scene.objects.link(obj)
bpy.ops.object.select_all(action = "DESELECT")
obj.select = True
context.scene.objects.active = obj
bpy.ops.object.mode_set(mode="EDIT")
return {"FINISHED"}
def register():
bpy.utils.register_module(__name__)
def unregister():
bpy.utils.unregister_module(__name__)