<!-- Generated by SpecStory, Markdown v2.1.0 -->

# 2026-03-10 16:25:21Z

<!-- cursoride Session daaa74ba-72d7-4686-a95b-ae6379d17ee9 (2026-03-10 16:25:21Z) -->

_**User**_

The DLM_OT_migrator_remove_original operator in T:\Dynamic-Link-Manager\ui\operators.py is failing with "StructRNA of type Collection has been removed" error.

This likely happens because:
1. The collection might be linked or an override that can't be removed directly
2. Other addons (like Animation Layers) might be holding references

Update the operator to:
1. First check if the collection is local (not linked) before trying to remove it
2. If collection removal fails, catch the specific error and fall back to removing just the objects in the collection
3. Handle the case where the collection is already being processed

Here's the improved logic:
```python
def execute(self, context):
    orig, rep = _get_migrator_pair(context)
    if not orig:
        self.report({"WARNING"}, "No original character selected")
        return {"CANCELLED"}
    if orig == rep:
        self.report({"ERROR"}, "Original and replacement cannot be the same object")
        return {"CANCELLED"}

    name = orig.name
    try:
        # Try to find the collection containing the original character
        coll = collection_containing_armature(orig)
        if coll and not coll.library:  # Only remove local collections
            # Get all objects in the collection before removing it
            objects_to_remove = list(coll.objects)
            # Remove the collection first
            bpy.data.collections.remove(coll)
            # Then remove the objects
            for obj in objects_to_remove:
                if obj and obj.name in bpy.data.objects:
                    bpy.data.objects.remove(obj, do_unlink=True)
            context.scene.dynamic_link_manager.original_character = None
            self.report({"INFO"}, f"Removed character collection: {coll.name}")
        else:
            # Fallback: just delete the armature object
            if orig.name in bpy.data.objects:
                bpy.data.objects.remove(orig, do_unlink=True)
            context.scene.dynamic_link_manager.original_character = None
            if coll:
                self.report({"INFO"}, f"Removed original (linked collection cannot be deleted): {name}")
            else:
                self.report({"INFO"}, f"Removed original character: {name}")
    except Exception as e:
        self.report({"ERROR"}, f"Failed to remove original: {e}")
        return {"CANCELLED"}
    return {"FINISHED"}
```

Make this change to the file.

---

_**Agent (accounts/fireworks/models/kimi-k2p5)**_

<think><details><summary>Thought Process</summary>
The user wants me to update the `DLM_OT_migrator_remove_original` operator in `T:\Dynamic-Link-Manager\ui\operators.py`. Let me first read the file to see the current implementation and then make the requested changes.</details></think>

_**Agent (accounts/fireworks/models/kimi-k2p5)**_

I'll read the current file to see the existing implementation of the operator.

_**Agent (accounts/fireworks/models/kimi-k2p5)**_

Cancelled

<tool-use data-tool-type="shell" data-tool-name="run_terminal_command_v2"><details>
<summary>Tool use: **run_terminal_command_v2**</summary>

</details></tool-use>
