1 # ##### BEGIN GPL LICENSE BLOCK #####
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software Foundation,
15 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 # ##### END GPL LICENSE BLOCK #####
25 def add_object_align_init(context, operator):
27 if operator and operator.properties.is_property_set("location") and operator.properties.is_property_set("rotation"):
28 location = mathutils.Matrix.Translation(mathutils.Vector(operator.properties.location))
29 rotation = mathutils.Euler(operator.properties.rotation).to_matrix().resize4x4()
31 # TODO, local view cursor!
32 location = mathutils.Matrix.Translation(context.scene.cursor_location)
34 if context.user_preferences.edit.object_align == 'VIEW' and context.space_data.type == 'VIEW_3D':
35 rotation = context.space_data.region_3d.view_matrix.rotation_part().invert().resize4x4()
37 rotation = mathutils.Matrix()
39 # set the operator properties
41 operator.properties.location = location.translation_part()
42 operator.properties.rotation = rotation.to_euler()
44 return location * rotation
47 def object_data_add(context, obdata, operator=None):
51 # ugh, could be made nicer
52 for ob in scene.objects:
55 obj_new = bpy.data.objects.new(obdata.name, obdata)
57 base = scene.objects.link(obj_new)
60 if context.space_data and context.space_data.type == 'VIEW_3D':
61 base.layers_from_view(context.space_data)
63 obj_new.matrix_world = add_object_align_init(context, operator)
65 obj_act = scene.objects.active
67 if obj_act and obj_act.mode == 'EDIT' and obj_act.type == obj_new.type:
68 bpy.ops.object.mode_set(mode='OBJECT')
71 scene.update() # apply location
72 #scene.objects.active = obj_new
74 bpy.ops.object.join() # join into the active.
76 bpy.ops.object.mode_set(mode='EDIT')
78 scene.objects.active = obj_new
79 if context.user_preferences.edit.use_enter_edit_mode:
80 bpy.ops.object.mode_set(mode='EDIT')