2
$\begingroup$

Found this one , it is 5 years old and i'm not happy with the answer :

are bpy.context.object and bpy.context.active_object STILL the same?

i'm curious if there is any new explanation about it ?

Thanks.

$\endgroup$
2
  • 1
    $\begingroup$ Still the same. What's your question? $\endgroup$
    – brockmann
    Dec 4, 2020 at 9:29
  • $\begingroup$ Just want to know if there's any specific case where we can't interchange them. Because i thought must be some reason to have both of them ? $\endgroup$
    – andio
    Dec 4, 2020 at 12:43

1 Answer 1

6
$\begingroup$

Some side cases.

There are some side cases. If we add

print(context.object, context.active_object)

Edited draw method

    def draw(self, context):
        print(context.object, context.active_object)
        layout = self.layout

        obj = context.object

        row = layout.row()
        row.label(text="Hello world!", icon='WORLD_DATA')

        row = layout.row()
        row.label(text="Active object is: " + obj.name)
        row = layout.row()
        row.prop(obj, "name")

        row = layout.row()
        row.operator("mesh.primitive_cube_add")

to the draw method of the Text Editor > Templates > Python > UI Panel Simple run the script, mouse over the panel and add or select sphere, it will spurt

<bpy_struct, Object("Sphere") at 0x7f05669b3c08> <bpy_struct, Object("Sphere") at 0x7f05669b3c08>

into the system console.

If we pin the sphere to the properties area, and add or select the Cone

enter image description here

will become

<bpy_struct, Object("Sphere") at 0x7f05669b3c08> <bpy_struct, Object("Cone") at 0x7f05669b6008>

ie in the context of the properties space, pinned to the sphere, that is the context object. The Cone is the context active object.

Also applies to an operator invoked from the pinned panel.

$\endgroup$
1
  • $\begingroup$ Cool! However, that's pretty rare, isn't it? Never noticed any difference... $\endgroup$
    – brockmann
    Dec 4, 2020 at 17:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .