2011-01-14 16:49:43 +00:00
|
|
|
bl_info = {
|
2010-12-22 18:43:21 +00:00
|
|
|
"name": "New Object",
|
2012-04-11 08:22:31 +00:00
|
|
|
"author": "Your Name Here",
|
2010-12-22 18:43:21 +00:00
|
|
|
"version": (1, 0),
|
2012-12-20 00:29:31 +00:00
|
|
|
"blender": (2, 65, 0),
|
2010-12-22 18:43:21 +00:00
|
|
|
"location": "View3D > Add > Mesh > New Object",
|
|
|
|
"description": "Adds a new Mesh Object",
|
|
|
|
"warning": "",
|
|
|
|
"wiki_url": "",
|
|
|
|
"category": "Add Mesh"}
|
|
|
|
|
|
|
|
|
|
|
|
import bpy
|
2012-04-11 08:22:31 +00:00
|
|
|
from bpy.types import Operator
|
2010-12-22 18:43:21 +00:00
|
|
|
from bpy.props import FloatVectorProperty
|
2012-04-11 08:22:31 +00:00
|
|
|
from bpy_extras.object_utils import AddObjectHelper, object_data_add
|
2010-12-22 18:43:21 +00:00
|
|
|
from mathutils import Vector
|
|
|
|
|
|
|
|
|
|
|
|
def add_object(self, context):
|
|
|
|
scale_x = self.scale.x
|
|
|
|
scale_y = self.scale.y
|
|
|
|
|
2011-01-26 07:54:27 +00:00
|
|
|
verts = [Vector((-1 * scale_x, 1 * scale_y, 0)),
|
|
|
|
Vector((1 * scale_x, 1 * scale_y, 0)),
|
|
|
|
Vector((1 * scale_x, -1 * scale_y, 0)),
|
|
|
|
Vector((-1 * scale_x, -1 * scale_y, 0)),
|
|
|
|
]
|
|
|
|
|
2010-12-22 18:43:21 +00:00
|
|
|
edges = []
|
2011-01-26 07:54:27 +00:00
|
|
|
faces = [[0, 1, 2, 3]]
|
2010-12-22 18:43:21 +00:00
|
|
|
|
2012-04-11 08:22:31 +00:00
|
|
|
mesh = bpy.data.meshes.new(name="New Object Mesh")
|
2011-03-22 01:38:26 +00:00
|
|
|
mesh.from_pydata(verts, edges, faces)
|
|
|
|
# useful for development when the mesh may be invalid.
|
|
|
|
# mesh.validate(verbose=True)
|
2012-04-11 08:22:31 +00:00
|
|
|
object_data_add(context, mesh, operator=self)
|
2010-12-22 18:43:21 +00:00
|
|
|
|
|
|
|
|
2012-04-11 08:22:31 +00:00
|
|
|
class OBJECT_OT_add_object(Operator, AddObjectHelper):
|
2012-09-29 11:51:18 +00:00
|
|
|
"""Create a new Mesh Object"""
|
2010-12-22 18:43:21 +00:00
|
|
|
bl_idname = "mesh.add_object"
|
|
|
|
bl_label = "Add Mesh Object"
|
|
|
|
bl_options = {'REGISTER', 'UNDO'}
|
|
|
|
|
2011-08-19 19:25:20 +00:00
|
|
|
scale = FloatVectorProperty(
|
2012-04-11 08:22:31 +00:00
|
|
|
name="scale",
|
2011-08-19 19:25:20 +00:00
|
|
|
default=(1.0, 1.0, 1.0),
|
|
|
|
subtype='TRANSLATION',
|
2012-04-11 08:22:31 +00:00
|
|
|
description="scaling",
|
2011-08-19 19:25:20 +00:00
|
|
|
)
|
2010-12-22 18:43:21 +00:00
|
|
|
|
|
|
|
def execute(self, context):
|
2011-01-26 07:54:27 +00:00
|
|
|
|
2010-12-22 18:43:21 +00:00
|
|
|
add_object(self, context)
|
2011-01-26 07:54:27 +00:00
|
|
|
|
2010-12-22 18:43:21 +00:00
|
|
|
return {'FINISHED'}
|
|
|
|
|
|
|
|
|
2011-03-22 01:38:26 +00:00
|
|
|
# Registration
|
2010-12-22 18:43:21 +00:00
|
|
|
|
|
|
|
def add_object_button(self, context):
|
|
|
|
self.layout.operator(
|
|
|
|
OBJECT_OT_add_object.bl_idname,
|
|
|
|
text="Add Object",
|
2012-07-04 21:41:05 +00:00
|
|
|
icon='PLUGIN')
|
2010-12-22 18:43:21 +00:00
|
|
|
|
2011-01-26 07:54:27 +00:00
|
|
|
|
2012-08-25 15:00:41 +00:00
|
|
|
# This allows you to right click on a button and link to the manual
|
|
|
|
def add_object_manual_map():
|
|
|
|
url_manual_prefix = "http://wiki.blender.org/index.php/Doc:2.6/Manual/"
|
|
|
|
url_manual_mapping = (
|
|
|
|
("bpy.ops.mesh.add_object", "Modeling/Objects"),
|
|
|
|
)
|
|
|
|
return url_manual_prefix, url_manual_mapping
|
|
|
|
|
|
|
|
|
2010-12-22 18:43:21 +00:00
|
|
|
def register():
|
2011-02-12 08:04:32 +00:00
|
|
|
bpy.utils.register_class(OBJECT_OT_add_object)
|
2012-08-25 15:00:41 +00:00
|
|
|
bpy.utils.register_manual_map(add_object_manual_map)
|
2010-12-22 18:43:21 +00:00
|
|
|
bpy.types.INFO_MT_mesh_add.append(add_object_button)
|
|
|
|
|
2012-09-26 21:19:51 +00:00
|
|
|
|
2010-12-22 18:43:21 +00:00
|
|
|
def unregister():
|
2011-02-12 08:04:32 +00:00
|
|
|
bpy.utils.unregister_class(OBJECT_OT_add_object)
|
2012-08-25 15:00:41 +00:00
|
|
|
bpy.utils.unregister_manual_map(add_object_manual_map)
|
2010-12-22 18:43:21 +00:00
|
|
|
bpy.types.INFO_MT_mesh_add.remove(add_object_button)
|
|
|
|
|
|
|
|
|
2012-04-11 08:22:31 +00:00
|
|
|
if __name__ == "__main__":
|
2010-12-22 18:43:21 +00:00
|
|
|
register()
|