[Bf-blender-cvs] [1e02a5f] master: Fix for object_utils.object_data_add: Now supports None obdata for creating empties.

Lukas Tönne noreply at git.blender.org
Wed Dec 10 17:26:08 CET 2014


Commit: 1e02a5ff433ab6fd387b71ffe525a56b8b5ea3b7
Author: Lukas Tönne
Date:   Wed Dec 10 17:22:26 2014 +0100
Branches: master
https://developer.blender.org/rB1e02a5ff433ab6fd387b71ffe525a56b8b5ea3b7

Fix for object_utils.object_data_add: Now supports None obdata for
creating empties.

The documentation says None is a valid argument for obdata (making
empties), but this would cause an exception. Now obdata is only used
when it is defined. An optional name argument can be passed to override
obdata.name as well.

===================================================================

M	release/scripts/modules/bpy_extras/object_utils.py

===================================================================

diff --git a/release/scripts/modules/bpy_extras/object_utils.py b/release/scripts/modules/bpy_extras/object_utils.py
index 0139076..13ef86b 100644
--- a/release/scripts/modules/bpy_extras/object_utils.py
+++ b/release/scripts/modules/bpy_extras/object_utils.py
@@ -99,7 +99,7 @@ def add_object_align_init(context, operator):
     return location * rotation
 
 
-def object_data_add(context, obdata, operator=None, use_active_layer=True):
+def object_data_add(context, obdata, operator=None, use_active_layer=True, name=None):
     """
     Add an object using the view context and preference to to initialize the
     location, rotation and layer.
@@ -110,6 +110,8 @@ def object_data_add(context, obdata, operator=None, use_active_layer=True):
     :type obdata: valid object data type or None.
     :arg operator: The operator, checked for location and rotation properties.
     :type operator: :class:`bpy.types.Operator`
+    :arg name: Optional name
+    :type name: string
     :return: the newly created object in the scene.
     :rtype: :class:`bpy.types.ObjectBase`
     """
@@ -119,7 +121,10 @@ def object_data_add(context, obdata, operator=None, use_active_layer=True):
     for ob in scene.objects:
         ob.select = False
 
-    obj_new = bpy.data.objects.new(obdata.name, obdata)
+    if name is None:
+        name = "Object" if obdata is None else obdata.name
+
+    obj_new = bpy.data.objects.new(name, obdata)
 
     base = scene.objects.link(obj_new)
     base.select = True
@@ -150,7 +155,7 @@ def object_data_add(context, obdata, operator=None, use_active_layer=True):
                 obj_act.mode == 'EDIT' and
                 obj_act.type == obj_new.type):
 
-            _obdata = bpy.data.meshes.new(obdata.name)
+            _obdata = bpy.data.meshes.new(name)
             obj_act = bpy.data.objects.new(_obdata.name, _obdata)
             obj_act.matrix_world = obj_new.matrix_world
             scene.objects.link(obj_act)
@@ -169,7 +174,8 @@ def object_data_add(context, obdata, operator=None, use_active_layer=True):
         #scene.objects.active = obj_new
 
         bpy.ops.object.join()  # join into the active.
-        bpy.data.meshes.remove(obdata)
+        if obdata:
+            bpy.data.meshes.remove(obdata)
         # base is freed, set to active object
         base = scene.object_bases.active




More information about the Bf-blender-cvs mailing list