Error trying to set only active object's origin with others selected I am new to scripting in blender/python, and I am unsure what I did wrong here. The script works fine until I try to make it work just with the active object. Then it throws the following error
Python: Traceback (most recent call last):   File &quot;C:\Users\Juantxopanza\AppData\Roaming\Blender Foundation\Blender\2.92\scripts\addons\snap_origin_addon.py&quot;, line 39, in execute
    curObject.origin_set(type='ORIGIN_CURSOR', center='MEDIAN') AttributeError: '_BPyOpsSubModOp' object has no attribute 'origin_set'

location: &lt;unknown location&gt;:-1

Here's the code:
bl_info = {
    &quot;name&quot;: &quot;Snap Origin to selected&quot;,
    &quot;author&quot;: &quot;&quot;,
    &quot;version&quot;: (0, 0),
    &quot;blender&quot;: (2, 90, 0),
    #&quot;location&quot;: &quot;View3D &gt; Mesh &gt; Snap &gt; Snap Origin to selected&quot;,
    &quot;description&quot;: &quot;snaps the origin of the object to a selection&quot;,
    &quot;category&quot;: &quot;Mesh&quot;,
}

import bpy
from bpy.props import (BoolProperty)
class MESH_OT_snapOrigin(bpy.types.Operator):
    &quot;&quot;&quot;It has to begin with a selected element in edit mode&quot;&quot;&quot;
    bl_idname = &quot;mesh.snap_origin_to_selected&quot;
    bl_label = &quot;Snap Origin to selected&quot;
    bl_options = {'REGISTER', 'UNDO'}
    
    only_active: bpy.props.BoolProperty(
        name=&quot;set only active&quot;,
        description=&quot;set only the origin of the active object&quot;,
        default=False,
    )
    

    @classmethod
    def poll(cls, context):
        return context.area.type == 'VIEW_3D'
    

    def execute(self, context):
        curObject = bpy.context.active_object
        get_3dCursor = (bpy.context.scene.cursor.location[0],bpy.context.scene.cursor.location[1],bpy.context.scene.cursor.location[2])
        print(bpy.context.active_object.name)
        #print(curObject.location[0])
        bpy.ops.view3d.snap_cursor_to_selected()
        bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
        if self.only_active == True:
           curObject.origin_set(type='ORIGIN_CURSOR', center='MEDIAN')
        else:
           bpy.ops.object.origin_set(type='ORIGIN_CURSOR', center='MEDIAN')
        # bpy.ops.object.origin_set(type='ORIGIN_CURSOR', center='MEDIAN')
        bpy.context.scene.cursor.location[0] = get_3dCursor[0]
        bpy.context.scene.cursor.location[1] = get_3dCursor[1]
        bpy.context.scene.cursor.location[2] = get_3dCursor[2]
        return {'FINISHED'}

# Registration

def set_origin_button(self, context):
    self.layout.operator(
        MESH_OT_snapOrigin.bl_idname,
        text=&quot;snap origin to selected&quot;,
        icon='PIVOT_CURSOR')
        
        
def register():
    bpy.utils.register_class(MESH_OT_snapOrigin)
    bpy.types.VIEW3D_MT_edit_mesh.append(set_origin_button)

def unregister():
    bpy.utils.unregister_class(MESH_OT_snapOrigin)
    bpy.types.VIEW3D_MT_edit_mesh.remove(set_origin_button)
Override the context.
There is no origin_set belonging to an Object.
There are a couple of ways to do this, either deselect all other objects before calling the origin set operator, or override the context to make the selection only the single (or chosen) object(s)
Am using the python console, which is a great place to nut things out.
With  &quot;Cube&quot; active, and the &quot;Cone&quot; and &quot;IcoSphere&quot; selected...
&gt;&gt;&gt; C.object
bpy.data.objects['Cube']

&gt;&gt;&gt; C.selected_objects
[bpy.data.objects['Cube'], bpy.data.objects['Icosphere'], bpy.data.objects['Cone']]

Make an override dictionary, telling blender the only object to re-origin-ate is the &quot;Cube&quot; by making it the only member of context.selected_editable_objects &lt;- The selected objects that the operator uses.  Why cannot I override the context for bpy.ops.object.origin_set()
&gt;&gt;&gt; c = {}
&gt;&gt;&gt; c['active_object'] = None
&gt;&gt;&gt; c['selected_editable_objects'] = [C.object]
&gt;&gt;&gt; c
{'active_object': None, 'selected_editable_objects': [bpy.data.objects['Cube']]}

Run the operator with that context dictionary c as the first argument.
&gt;&gt;&gt; bpy.ops.object.origin_set(c, type='ORIGIN_CURSOR')
{'FINISHED'}

and only the origin of the active object is set.
The error in your question relates to the Object
not having an origin_set property.
&gt;&gt;&gt; C.object.origin_set
Traceback (most recent call last):
  File &quot;&lt;blender_console&gt;&quot;, line 1, in &lt;module&gt;
AttributeError: 'Object' object has no attribute 'origin_set'