I created a city scene which has a vehicle model inside, I need to duplicate the vehicle model to display a dozen of them in the city scene through python API. The vehicle object name is BMWM1. I have tried on these two approaches
Approach 1 from stackoverflow
scn = bpy.context.scene
new_obj = bpy.data.objects["BMWM1"].copy()
new_obj.data = bpy.data.objects["BMWM1"].data.copy()
new_obj.animation_data_clear()
scn.objects.link(new_obj)
new_obj.location = (-8, 6, 2)
scn.objects.active = new_obj
new_obj.select = True
Approach 2
bpy.data.objects['BMWM1'].select = True
new_obj = bpy.ops.object.duplicate()
scn.objects.link(new_obj)
new_obj.location = (-8, 6, 2)
scn.objects.active = new_obj
new_obj.select = True
Both approaches received a error saying
"warning DM_ensure_tessface: could not create tessfaces from 144 polygons, dm->type=2 warning DM_ensure_tessface: could not create tessfaces from 144 polygons, dm->type=2 "
And the second approach additionally received a error:
" scn.objects.link(new_obj) TypeError: SceneObjects.link(): error with argument 1, "object" - Function.object expected a Object type, not set "
I have also seen the tutorials like Three ways to create objects, two ways to create a new object
Add the data, and then the object. For a mesh:
me = bpy.data.meshes.new(meshName)
ob = bpy.data.objects.new(obName, me)
and for an armature:
amt = bpy.data.armatures.new(amtname)
ob = bpy.data.objects.new(obname, amt)
While I tried another way
me = bpy.data.objects["BMWM1"].data;
me_copy = me.copy()
new_obj = bpy.data.objects.new("BMWM1",me_copy)
scn.objects.link(new_obj)
new_obj.location = (-8, 6, 2)
scn.objects.active = new_obj
new_obj.select = True
but still at the end the error
"warning DM_ensure_tessface: could not create tessfaces from 144 polygons, dm->type=2 warning DM_ensure_tessface: could not create tessfaces from 144 polygons, dm->type=2 "
happened again
I tried the duplicate again as commented by
bpy.data.objects['BMWM1'].select = True
set = bpy.ops.object.duplicate()
for new_obj in set:
scn.objects.link(new_obj)
still produced a error
scn.objects.link(new_obj) TypeError: SceneObjects.link(): error with argument 1, "object" - Function.object expected a Object type, not str
set = bpy.ops.object.duplicate(), for new_obj in set
, but still has a error scn.objects.link(new_obj) TypeError: SceneObjects.link(): error with argument 1, "object" - Function.object expected a Object type, not str $\endgroup$bpy.data.objects.new(...)
. Is the tessface error similar to the one outlined here? $\endgroup$