diff --git a/release/scripts/extensions/add_mesh_gears.py b/release/scripts/extensions/add_mesh_gears.py index a7e08f7a3bc..4c286215353 100644 --- a/release/scripts/extensions/add_mesh_gears.py +++ b/release/scripts/extensions/add_mesh_gears.py @@ -322,8 +322,7 @@ class AddGear(bpy.types.Operator): mesh.update() - ob_new = bpy.data.objects.new('Gear','MESH') - ob_new.data = mesh + ob_new = bpy.data.objects.new('Gear', mesh) tipgroup = ob_new.add_vertex_group('Tips') # for some reason the name does not 'stick' and we have to set it this way: diff --git a/release/scripts/io/export_obj.py b/release/scripts/io/export_obj.py index aa9968d71ad..b633aeb385c 100644 --- a/release/scripts/io/export_obj.py +++ b/release/scripts/io/export_obj.py @@ -447,8 +447,7 @@ def write(filename, objects, scene, break if has_quads: - newob = bpy.data.objects.new('temp_object', 'MESH') - newob.data = me + newob = bpy.data.objects.new('temp_object', me) # if we forget to set Object.data - crash scene.objects.link(newob) newob.convert_to_triface(scene) diff --git a/release/scripts/io/import_anim_bvh.py b/release/scripts/io/import_anim_bvh.py index 97dfbcba5b6..364bd6e96ee 100644 --- a/release/scripts/io/import_anim_bvh.py +++ b/release/scripts/io/import_anim_bvh.py @@ -295,7 +295,7 @@ def bvh_node_dict2objects(context, bvh_nodes, IMPORT_START_FRAME=1, IMPORT_LOOP= objects = [] def add_ob(name): - ob = scn.objects.new('Empty') + ob = scn.objects.new('Empty', None) objects.append(ob) return ob @@ -352,8 +352,7 @@ def bvh_node_dict2armature(context, bvh_nodes, ROT_MODE='XYZ', IMPORT_START_FRAM scn.set_frame(IMPORT_START_FRAME) arm_data = bpy.data.armatures.new("MyBVH") - arm_ob = bpy.data.objects.new("MyBVH", 'ARMATURE') - arm_ob.data = arm_data + arm_ob = bpy.data.objects.new("MyBVH", arm_data) scn.objects.link(arm_ob) diff --git a/release/scripts/io/import_scene_3ds.py b/release/scripts/io/import_scene_3ds.py index aea07d47dd9..5b41517ee71 100644 --- a/release/scripts/io/import_scene_3ds.py +++ b/release/scripts/io/import_scene_3ds.py @@ -418,8 +418,7 @@ def process_next_chunk(file, previous_chunk, importedObjects, IMAGE_SEARCH): uf.tex = True # bmesh.transform(contextMatrix) - ob = bpy.data.objects.new(tempName, 'MESH') - ob.data = bmesh + ob = bpy.data.objects.new(tempName, bmesh) SCN.objects.link(ob) # ob = SCN_OBJECTS.new(bmesh, tempName) ''' @@ -638,8 +637,7 @@ def process_next_chunk(file, previous_chunk, importedObjects, IMAGE_SEARCH): x,y,z = struct.unpack('<3f', temp_data) new_chunk.bytes_read += STRUCT_SIZE_3FLOAT - ob = bpy.data.objects.new("Lamp", 'LAMP') - ob.data = bpy.data.lamps.new("Lamp") + ob = bpy.data.objects.new("Lamp", bpy.data.lamps.new("Lamp")) SCN.objects.link(ob) contextLamp[1]= ob.data diff --git a/release/scripts/io/import_scene_obj.py b/release/scripts/io/import_scene_obj.py index 86dd1b4920d..0249d6c6047 100644 --- a/release/scripts/io/import_scene_obj.py +++ b/release/scripts/io/import_scene_obj.py @@ -863,10 +863,8 @@ def create_mesh(scn, new_objects, has_ngons, CREATE_FGONS, CREATE_EDGES, verts_l me.update() # me.calcNormals() - ob= bpy.data.objects.new("Mesh", 'MESH') - ob.data= me + ob= bpy.data.objects.new("Mesh", me) scn.objects.link(ob) -# ob= scn.objects.new(me) new_objects.append(ob) # Create the vertex groups. No need to have the flag passed here since we test for the diff --git a/release/scripts/modules/rigify/__init__.py b/release/scripts/modules/rigify/__init__.py index 8cb7a926c06..895afd20d59 100644 --- a/release/scripts/modules/rigify/__init__.py +++ b/release/scripts/modules/rigify/__init__.py @@ -182,8 +182,7 @@ def generate_rig(context, obj_orig, prefix="ORG-", META_DEF=True): try: obj = scene.objects[name] except KeyError: - obj = bpy.data.objects.new(name, type='ARMATURE') - obj.data = bpy.data.armatures.new(name) + obj = bpy.data.objects.new(name, bpy.data.armatures.new(name)) scene.objects.link(obj) obj.data.pose_position = 'POSE' @@ -487,9 +486,8 @@ def generate_test(context, metarig_type="", GENERATE_FINAL=True): scene = context.scene def create_empty_armature(name): - obj_new = bpy.data.objects.new(name, 'ARMATURE') armature = bpy.data.armatures.new(name) - obj_new.data = armature + obj_new = bpy.data.objects.new(name, armature) scene.objects.link(obj_new) scene.objects.active = obj_new for obj in scene.objects: diff --git a/release/scripts/op/add_mesh_torus.py b/release/scripts/op/add_mesh_torus.py index 860ac93954a..4ebf1ff028c 100644 --- a/release/scripts/op/add_mesh_torus.py +++ b/release/scripts/op/add_mesh_torus.py @@ -130,8 +130,7 @@ class AddTorus(bpy.types.Operator): ob.selected = False mesh.update() - ob_new = bpy.data.objects.new("Torus", 'MESH') - ob_new.data = mesh + ob_new = bpy.data.objects.new("Torus", mesh) scene.objects.link(ob_new) ob_new.selected = True diff --git a/release/scripts/op/object.py b/release/scripts/op/object.py index cb243e66e29..1c0f6d3d9c5 100644 --- a/release/scripts/op/object.py +++ b/release/scripts/op/object.py @@ -447,13 +447,11 @@ class MakeDupliFace(bpy.types.Operator): # pick an object to use obj = objects[0] - ob_new = bpy.data.objects.new(mesh.name, 'MESH') - ob_new.data = mesh + ob_new = bpy.data.objects.new(mesh.name, mesh) base = scene.objects.link(ob_new) base.layers[:] = obj.layers - ob_inst = bpy.data.objects.new(data.name, obj.type) - ob_inst.data = data + ob_inst = bpy.data.objects.new(data.name, data) base = scene.objects.link(ob_inst) base.layers[:] = obj.layers diff --git a/source/blender/makesrna/intern/rna_main_api.c b/source/blender/makesrna/intern/rna_main_api.c index e937a3b10c2..56c0819680d 100644 --- a/source/blender/makesrna/intern/rna_main_api.c +++ b/source/blender/makesrna/intern/rna_main_api.c @@ -30,6 +30,7 @@ #include #include "RNA_define.h" +#include "RNA_access.h" #include "RNA_types.h" #include "RNA_enum_types.h" @@ -38,6 +39,7 @@ #ifdef RNA_RUNTIME #include "BKE_main.h" +#include "BKE_curve.h" #include "BKE_mesh.h" #include "BKE_armature.h" #include "BKE_library.h" @@ -109,12 +111,54 @@ void rna_Main_scenes_remove(Main *bmain, bContext *C, ReportList *reports, struc unlink_scene(bmain, scene, newscene); } -Object *rna_Main_objects_new(Main *bmain, char* name, int type) +Object *rna_Main_objects_new(Main *bmain, ReportList *reports, char* name, ID *data) { - Object *ob= add_only_object(type, name); + Object *ob; + int type= OB_EMPTY; + if(data) { + switch(GS(data->name)) { + case ID_ME: + type= OB_MESH; + break; + case ID_CU: + type= curve_type((struct Curve *)data); + break; + case ID_MB: + type= OB_MBALL; + break; + case ID_LA: + type= OB_LAMP; + break; + case ID_CA: + type= OB_CAMERA; + break; + case ID_LT: + type= OB_LATTICE; + break; + case ID_AR: + type= OB_ARMATURE; + break; + default: + { + const char *idname; + if(RNA_enum_id_from_value(id_type_items, GS(data->name), &idname) == 0) + idname= "UNKNOWN"; + + BKE_reportf(reports, RPT_ERROR, "ID type '%s' is not valid for a object.", idname); + return NULL; + } + } + + data->us++; + } + + ob= add_only_object(type, name); ob->id.us--; + + ob->data= data; return ob; } + void rna_Main_objects_remove(Main *bmain, ReportList *reports, struct Object *object) { /* @@ -337,10 +381,11 @@ void RNA_def_main_objects(BlenderRNA *brna, PropertyRNA *cprop) RNA_def_struct_ui_text(srna, "Main Objects", "Collection of objects"); func= RNA_def_function(srna, "new", "rna_Main_objects_new"); + RNA_def_function_flag(func, FUNC_USE_REPORTS); RNA_def_function_ui_description(func, "Add a new object to the main database"); parm= RNA_def_string(func, "name", "Object", 0, "", "New name for the datablock."); RNA_def_property_flag(parm, PROP_REQUIRED); - parm= RNA_def_enum(func, "type", object_type_items, 0, "", "Type of Object."); + parm= RNA_def_pointer(func, "object_data", "ID", "", "Object data or None for an empty object."); RNA_def_property_flag(parm, PROP_REQUIRED); /* return type */