Maniphest T101971

Python API, When use outliner.collection_duplicate i get "ERROR: No active collection"
Closed, Archived

Assigned To
None
Authored By
zebus3d (ofuscado)
Oct 21 2022, 11:14 AM
Tags
  • BF Blender
Subscribers
Germano Cavalcante (mano-wii)
zebus3d (ofuscado)

Description

System Information
Operating system: Linux-5.19.0-2-amd64-x86_64-with-glibc2.35 64 Bits
Graphics card: NVIDIA GeForce RTX 3070/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 470.141.03

Blender Version
Broken: version: 3.3.0, branch: master, commit date: 2022-09-06 15:39, hash: rB0759f671ce1f
Worked: (newest version of Blender that worked as expected)

Short description of error
When I try to duplicate a collection from python it tells me that there is no active collection and in fact there is.

Here is my example script:

context = bpy.context
coll_name = "test1"

def recurLayerCollection(context, layerColl, collName):
    found = None
    if (layerColl.name == collName):
        return layerColl
    #
    for layer in layerColl.children:
        found = recurLayerCollection(context, layer, collName)
        if found:
            return found

root_layerColl = context.view_layer.layer_collection
to_coll = recurLayerCollection(context, root_layerColl, coll_name)
bpy.data.scenes[context.scene.name].view_layers[context.view_layer.name].active_layer_collection = to_coll

print('Active collection:', context.view_layer.active_layer_collection.collection.name)
for window in context.window_manager.windows:
    screen = window.screen
    for area in screen.areas:
        if area.type == 'OUTLINER':
            override = {'window': window, 'screen': screen, 'area': area}
            bpy.ops.outliner.collection_duplicate(override)
            break

Exact steps for others to reproduce the error

Event Timeline

zebus3d (ofuscado) created this task.Oct 21 2022, 11:14 AM
zebus3d (ofuscado) updated the task description.
Germano Cavalcante (mano-wii) closed this task as Archived.Oct 21 2022, 7:06 PM
Germano Cavalcante (mano-wii) added a subscriber: Germano Cavalcante (mano-wii).

This is yet another case where the operator does not use the context and uses its own means to detect the "first selected collection". (Similar to T101910: Make Single User operator does not override)
See rB source/blender/editors/space_outliner/outliner_collections.cc:581

While it may be interesting to make the operator use context, this is not considered a bug.

For user requests and feedback, you can use other channels: https://wiki.blender.org/wiki/Communication/Contact#User_Feedback_and_Requests

For more information on why this isn't considered a bug, visit: https://wiki.blender.org/wiki/Reference/Not_a_bug