2
$\begingroup$

I am trying to invoke bpy.ops.outliner.group_operation(type='LINK') in an addon but unable to get the right context.

From a bit of searching, it appears I would need to have the OUTLINER area active before calling the op, but cannot figure out how to do that.

How can I set the right context in order to call bpy.ops.outliner.group_operation()?

Edit: The ultimate objective is to 'Link Group objects to Scene' which is an option available in the context menu for a group. I managed to make it run by overriding the context but it doesn't appear to actually do anything when run this way.

$\endgroup$
2
  • $\begingroup$ I think it would be useful if you could give some context as to what you are attempting as it may turn out that there is a better alternative to group_operation. $\endgroup$ Commented Mar 4, 2017 at 16:49
  • 1
    $\begingroup$ @RayMairlot thanks for the suggestion. I have edited the question. $\endgroup$
    – RSS
    Commented Mar 4, 2017 at 17:20

1 Answer 1

1
$\begingroup$

Overriding the context finally worked for me, with the help of this answer:

override = bpy.context.copy()
for area in bpy.context.screen.areas:
    if area.type == 'OUTLINER':
        override['area'] = area
bpy.ops.outliner.group_operation(override, type='LINK')
$\endgroup$
2
  • 1
    $\begingroup$ I gave this a try, but couldn't get it going due to having to have the group highlighted in the Outliner. Without the highlight, it wouldn't work. What is your workaround? How did you make it target a specific group? $\endgroup$
    – Draise
    Commented Aug 18, 2017 at 22:41
  • $\begingroup$ check this blender.stackexchange.com/questions/6101/… $\endgroup$
    – Harry McKenzie
    Commented Jul 30, 2022 at 2:07

You must log in to answer this question.

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