I try to copy my model and append it as child.
When I try to duplicate by bpy.ops.object.duplicate()
.
It will return {'FINISHED'}
which is not useful for accessing it!
I can't put any operation when the item id is unknown!
Blender Stack Exchange is a question and answer site for people who use Blender to create 3D graphics, animations, or games. It only takes a minute to sign up.
Sign up to join this communityIf you need the object for further operations it's best to do the duplication without the operator.
data_copy = bpy.data.objects["Cube"].data.copy()
obj_copy = bpy.data.objects["Cube"].copy()
obj_copy.data = data_copy
bpy.data.collections["Collection"].objects.link(obj_copy)
obj_copy.parent = bpy.data.objects["Cube"]
It is best to do it without the operator like in the answer by rjg, however after the operator is run the duplicated object becomes the active object, so it's bpy.context.object
and if you are duplicating a few objects, all the duplicates become selected so they are all in bpy.context.selected_objects
.