opsbpy.ops
is a module directly in the bpybpy
, not part of theany object class.It stores It holds all availableregistered operators. If you don't specify a region, it will always assume you want to do something in the viewport. Just replace src_objsrc_obj
with bpy. However just as it would be when pressing SHIF Dbpy
to match the behavior of ShiftD.
You should also make sure that the cube is the active objectactive object.
bpy.context.view_layer.objects.active = src_obj
scr_obj.select_set(True)
bpy.ops.object.duplicate(linked=0,mode='TRANSLATION')
new_obj = bpy.context.active_object