Blender Errors Context 标志

Blender Errors Context

组织
Impertio-Studio
blender-errors-context

Use when debugging Blender RuntimeError from restricted context, operator poll() failures, or wrong context for bpy.ops calls. Prevents the #1 Blender Python error: calling operators or accessing context attributes from wrong areas (e.g., timer callbacks, draw handlers). Covers context override removal in 4.0+, temp_override migration, and context-dependent attribute access patterns. Keywords: RuntimeError, restricted context, poll failure, context override, temp_override, bpy.ops error, wrong context, modal context, Blender context error, operator not available, cannot call operator.

概览

发布者Impertio-Studio
代码仓库Blender-Bonsai-ifcOpenshell-Sverchok-Claude-Skill-Package
技能名称blender-errors-context
星标数
44
复刻数
5
附带文件
3
许可协议MIT
链接
  • Markdown 格式的指令

    模型按需加载 SKILL.md 文件,因此只有在请求确实与该技能匹配时才会消耗 Token。

  • 兼容任何大语言模型

    AI 技能采用纯 Markdown,而非特定提供商的代码,因此可搭配 GPT、Claude、Gemini、Grok 或本地模型使用。

  • 3 个附带文件

    模型执行任务时可读取的脚本、模板和参考资料。这些文件为只读文件,绝不会被执行。

  • 开源

    由 Impertio-Studio 发布于 GitHub。请在安装前查看技能的源文件。

安装

在 TypingMind 中安装 Blender Errors Context AI 技能,即可搭配任意大语言模型使用;也可以将其放入其他支持读取 SKILL.md 的智能体中。

1

安装到 TypingMind

TypingMind 可直接从 GitHub 文件夹安装技能:读取 SKILL.md,打包资源文件,并将结果保存在本地。

  1. 打开应用,前往“插件 → 技能”。
  2. 选择“从 GitHub 安装”。
  3. 粘贴下方的技能文件夹 URL 并确认。
    https://github.com/Impertio-Studio/Blender-Bonsai-ifcOpenshell-Sverchok-Claude-Skill-Package/tree/main/skills/blender/errors/blender-errors-context
  4. 请在每个需要使用该技能的聊天中启用它。
依次选择“插件 → 技能 → 添加技能 → 从 GitHub URL 导入”,然后粘贴文件夹 URL 并点击“继续”。
2

安装到其他智能体

任何支持 Agent Skills 格式的智能体都可以使用此技能,只需将文件夹复制到该智能体的技能目录中。

Claude Code — .claude/skills
git clone --depth 1 https://github.com/Impertio-Studio/Blender-Bonsai-ifcOpenshell-Sverchok-Claude-Skill-Package.git /tmp/Blender-Bonsai-ifcOpenshell-Sverchok-Claude-Skill-Package
mkdir -p .claude/skills
cp -r /tmp/Blender-Bonsai-ifcOpenshell-Sverchok-Claude-Skill-Package/skills/blender/errors/blender-errors-context .claude/skills/blender-errors-context
复制后,请重启 Claude Code,以加载新技能。

在 TypingMind 中使用此技能

在任意 TypingMind 聊天中启用 Blender Errors Context,后续即可交由模型处理。技能的名称和描述会放在系统提示词中,一旦请求匹配,模型就会自动加载完整指令,无需您手动调用,且在实际使用前不会消耗 Token。

一旦请求与技能匹配,模型就会自动加载 Blender Errors Context。

兼容任何 AI 模型

AI 技能是纯 Markdown 指令,而非特定提供商的代码,因此 Blender Errors Context 不局限于最初适配的模型。只需在 TypingMind 中安装一次,即可搭配 GPT-5、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 或您自行运行的本地模型使用,全程使用您自己的 API 密钥。

  • 仅在需要时加载

    系统提示词中仅包含技能名称和描述。首次遇到匹配的请求时才会加载完整指令,因此技能未使用时,这些指令不会消耗 Token。

  • 在聊天中切换模型

    技能是指令而非代码,因此切换模型不会导致技能失效,新模型会读取同一个 SKILL.md。

技能指令

这是模型会加载的 SKILL.md 内容。请在安装前阅读,因为技能就是模型将遵循的指令。

Blender Context Errors: Diagnosis and Resolution

Purpose

This skill enables diagnosis and resolution of Blender Python context errors. Context errors are the most common category of Blender scripting failures. They occur when code accesses bpy.context members or calls bpy.ops operators in situations where the required context is unavailable, restricted, or incorrectly configured.

Scope

  • RuntimeError from restricted context access (handlers, timers, draw callbacks)
  • Operator poll() failures and incorrect context for bpy.ops calls
  • Context override removal in Blender 4.0+ and temp_override() migration
  • Modal operator context issues
  • Context-dependent attribute access (bpy.context.active_object, bpy.context.edit_object)
  • Stale references after undo, data modification, or mode changes

Version coverage: Blender 3.x, 4.x, 5.x. Version-breaking changes are marked explicitly.

Dependencies: This skill builds on blender-core-api (context system basics) and blender-syntax-operators (operator patterns).


1. Context Error Categories

1.1 RuntimeError: Restricted Context

When: Code runs in a context where bpy.context is partially or fully unavailable.

Restricted contexts:

  • depsgraph_update_post / depsgraph_update_pre handlers
  • render_pre / render_post / render_write handlers
  • draw() methods of bpy.types.Panel, bpy.types.Header, bpy.types.Menu
  • bpy.app.timers callbacks
  • Background threads (NEVER access bpy.context from threads)

Error messages:

RuntimeError: restricted context element 'active_object'
RuntimeError: Calling operator "bpy.ops.object.select_all" error, can't modify blend data in this state

Rule: In restricted contexts, use bpy.data for read-only access. NEVER call bpy.ops or modify blend data. To defer work to a safe context, use bpy.app.timers.register().

python
# Blender 3.2+
import bpy

def my_handler(scene, depsgraph):
    # WRONG: bpy.context.active_object raises RuntimeError
    # WRONG: bpy.ops.object.delete() raises RuntimeError

    # CORRECT: read-only access via bpy.data
    obj = bpy.data.objects.get("Cube")
    if obj is not None:
        print(obj.location)

    # CORRECT: defer modifications to a timer
    def deferred():
        bpy.data.objects["Cube"].location.x += 1.0
        return None  # do not repeat
    bpy.app.timers.register(deferred)

bpy.app.handlers.depsgraph_update_post.append(my_handler)

1.2 Operator poll() Failures

When: An operator's poll() classmethod returns False because required context conditions are not met.

Error message:

RuntimeError: Operator bpy.ops.object.mode_set.poll() failed, context is incorrect

Common causes:

OperatorRequired context
bpy.ops.object.mode_set()Active object exists, is visible, is selectable
bpy.ops.mesh.subdivide()Active object is mesh, in Edit Mode
bpy.ops.object.parent_set()2+ objects selected, one active
bpy.ops.uv.unwrap()Active mesh in Edit Mode, UV map exists
bpy.ops.object.convert()Active object exists, correct type

Rule: ALWAYS check poll() before calling an operator, OR set up the required context explicitly.

python
# Blender 3.2+
import bpy

obj = bpy.data.objects.get("Cube")
if obj is None:
    raise RuntimeError("Object 'Cube' not found")

# Ensure context: select and activate
bpy.context.view_layer.objects.active = obj
obj.select_set(True)

# Check poll before calling
if bpy.ops.object.mode_set.poll():
    bpy.ops.object.mode_set(mode='EDIT')

1.3 Context Override Errors (Version-Critical)

BREAKING CHANGE in Blender 4.0: Dictionary-based context overrides are REMOVED.

python
# Blender 3.x ONLY: REMOVED in 4.0
override = bpy.context.copy()
override['area'] = area
override['region'] = region
bpy.ops.view3d.camera_to_view(override)  # TypeError in 4.0+

Blender 3.2+ (REQUIRED in 4.0+): Use bpy.context.temp_override().

python
# Blender 3.2+ (works in 3.2, 3.3, ..., 4.0, 4.1, ..., 5.x)
import bpy

area = next(a for a in bpy.context.screen.areas if a.type == 'VIEW_3D')
region = next(r for r in area.regions if r.type == 'WINDOW')

with bpy.context.temp_override(area=area, region=region):
    bpy.ops.view3d.camera_to_view()

Rule: ALWAYS use bpy.context.temp_override() for context overrides. NEVER use dictionary-based overrides — they fail silently in 3.6 and raise TypeError in 4.0+.

1.4 Modal Operator Context

When: Modal operators lose context between invoke() and modal() calls, or access area/region data that changes between frames.

Rule: Store required context references during invoke(). Do NOT rely on bpy.context.area or bpy.context.region persisting in modal().

python
# Blender 3.2+
import bpy

class EXAMPLE_OT_modal(bpy.types.Operator):
    bl_idname = "example.modal_op"
    bl_label = "Modal Example"

    def invoke(self, context, event):
        # Store references during invoke
        self._area = context.area
        self._region = context.region
        context.window_manager.modal_handler_add(self)
        return {'RUNNING_MODAL'}

    def modal(self, context, event):
        if event.type == 'ESC':
            return {'CANCELLED'}
        # Use stored references, not context.area
        if self._area.type != 'VIEW_3D':
            return {'CANCELLED'}
        return {'PASS_THROUGH'}

1.5 Context-Dependent Attribute Access

When: Code accesses bpy.context attributes that are only available in specific editor types or modes.

Attributes with context requirements:

AttributeRequires
context.edit_objectObject in Edit Mode
context.active_boneArmature in Edit Mode
context.active_pose_boneArmature in Pose Mode
context.sculpt_objectObject in Sculpt Mode
context.image_paint_objectObject in Texture Paint Mode
context.selected_editable_bonesArmature in Edit Mode
context.visible_pose_bonesArmature in Pose Mode

Rule: ALWAYS check mode before accessing mode-specific context attributes. These attributes return None or raise AttributeError when the mode does not match.

python
# Blender 3.2+
import bpy

# WRONG: may be None if not in Edit Mode
# verts = bpy.context.edit_object.data.vertices

# CORRECT: check mode first
obj = bpy.context.active_object
if obj is not None and obj.mode == 'EDIT':
    edit_obj = bpy.context.edit_object
    # work with edit_obj

2. Stale Reference Errors

2.1 Undo Invalidates All References

When: After bpy.ops.ed.undo() or user Ctrl+Z, ALL previously stored references to Blender data become invalid.

Error message:

ReferenceError: StructRNA of type Object has been removed

Rule: NEVER store persistent references to bpy.types instances across operations that may trigger undo. Re-fetch by name after undo.

python
# Blender 3.2+
import bpy

# WRONG: reference becomes stale after undo
obj = bpy.data.objects["Cube"]
bpy.ops.ed.undo()
print(obj.location)  # ReferenceError

# CORRECT: re-fetch after undo
obj_name = "Cube"
bpy.ops.ed.undo()
obj = bpy.data.objects.get(obj_name)
if obj is not None:
    print(obj.location)

2.2 Data Modification Invalidates References

When: Operations that add or remove data blocks (objects, meshes, materials) may invalidate existing Python references to the same collection.

Rule: After any operation that modifies bpy.data collections, re-fetch references by name. NEVER iterate a collection while modifying it.

python
# Blender 3.2+
import bpy

# WRONG: modifying collection during iteration
for obj in bpy.data.objects:
    bpy.data.objects.remove(obj)  # invalidates iterator

# CORRECT: collect names first, then remove
names = [obj.name for obj in bpy.data.objects if obj.type == 'MESH']
for name in names:
    obj = bpy.data.objects.get(name)
    if obj is not None:
        bpy.data.objects.remove(obj)

2.3 Mode Change Invalidates Mesh References

When: Switching between Object Mode and Edit Mode invalidates bmesh.from_edit_mesh() references and mesh data access patterns.

Rule: ALWAYS obtain fresh mesh/bmesh references after mode changes. Free BMesh instances when done.

python
# Blender 3.2+
import bpy
import bmesh

obj = bpy.context.active_object
bpy.ops.object.mode_set(mode='EDIT')

bm = bmesh.from_edit_mesh(obj.data)
bm.verts.ensure_lookup_table()

# ... perform edits ...

bmesh.update_edit_mesh(obj.data)
# Do NOT call bm.free() for from_edit_mesh: Blender manages it

bpy.ops.object.mode_set(mode='OBJECT')
# bm is now INVALID: do not use

3. Resolution Decision Tree

When encountering a context error, follow this sequence:

1. Is the error "restricted context element"?
   YES → Code runs in a handler, timer, or draw callback.
         → Use bpy.data for read-only access.
         → Defer modifications with bpy.app.timers.register().

2. Is the error "poll() failed"?
   YES → Check operator requirements (mode, selection, active object).
         → Set up context: activate object, set mode, ensure selection.
         → Use temp_override() if area/region context is needed.

3. Is the error about context overrides (TypeError)?
   YES → Blender 4.0+ removed dict-based overrides.
         → Migrate to bpy.context.temp_override().
         → See §1.3 for migration pattern.

4. Is the error "StructRNA has been removed"?
   YES → Reference invalidated by undo or data modification.
         → Re-fetch by name from bpy.data.
         → See §2 for patterns.

5. Is the attribute None unexpectedly?
   YES → Context attribute requires specific mode or editor type.
         → Check mode before access.
         → See §1.5 for attribute requirements.

4. Version Migration Reference

4.0 Context Override Removal

AspectBlender 3.xBlender 4.0+
Context override syntaxop(override_dict, ...)REMOVED — TypeError
Recommended syntaxtemp_override() (3.2+)temp_override() (required)
bpy.context.copy() for overridesWorks but deprecatedREMOVED

temp_override() Availability

Blender Versiontemp_override()Dict overrides
3.0–3.1NOT availableWorks
3.2–3.6AvailableWorks (deprecated)
4.0+RequiredREMOVED

Version Detection Pattern

python
# Blender 3.2+
import bpy

def call_with_override(area, region, op_func, **kwargs):
    """Call operator with context override, version-aware."""
    if bpy.app.version >= (3, 2, 0):
        with bpy.context.temp_override(area=area, region=region):
            return op_func(**kwargs)
    else:
        override = bpy.context.copy()
        override['area'] = area
        override['region'] = region
        return op_func(override, **kwargs)

Note: The version-detection pattern above is provided for migration of legacy code. For new code, ALWAYS target Blender 3.2+ and use temp_override() exclusively.


5. Threading Rules

Rule: NEVER access bpy.context, bpy.ops, or modify bpy.data from background threads.

Error:

RuntimeError: can't modify blend data outside main thread

Resolution: Use bpy.app.timers.register() to schedule work on the main thread.

python
# Blender 3.2+
import bpy
import threading

def background_work():
    result = expensive_computation()

    def apply_result():
        bpy.data.objects["Cube"].location.x = result
        return None  # do not repeat
    bpy.app.timers.register(apply_result)

thread = threading.Thread(target=background_work)
thread.start()

6. Quick Reference: Error Message Index

Error MessageSectionResolution
RuntimeError: restricted context element '...'§1.1Use bpy.data, defer with timers
RuntimeError: Operator ... poll() failed§1.2Set up context, check poll()
TypeError: ... takes N positional arguments (4.0+)§1.3Migrate to temp_override()
ReferenceError: StructRNA of type ... has been removed§2.1Re-fetch by name
RuntimeError: can't modify blend data outside main thread§5Use bpy.app.timers.register()
AttributeError: 'NoneType' has no attribute ... on context§1.5Check mode before access

References

  • references/methods.md — Context-related API signatures
  • references/examples.md — Working error resolution examples
  • references/anti-patterns.md — Common context mistakes with corrections

Approved Sources

附带文件

技能加载后,模型会按需读取这些文件。它们仅作为可读文件提供,绝不会被执行。

常见问题

Blender Errors Context AI 技能有什么作用?

Use when debugging Blender RuntimeError from restricted context, operator poll() failures, or wrong context for bpy.ops calls. Prevents the #1 Blender Python error: calling operators or accessing context attributes from wrong areas (e.g., timer callbacks, draw handlers). Covers context override removal in 4.0+, temp_override migration, and context-dependent attribute access patterns. Keywords: RuntimeError, restricted context, poll failure, context override, temp_override, bpy.ops error, wrong context, modal context, Blender context error, operator not available, cannot call operator.

为什么在 TypingMind 中使用 Blender Errors Context?

因为您只需安装一次,就能搭配任何模型使用。Blender Errors Context 采用纯 Markdown 格式,而非特定提供商专用的代码,因此同一技能可用于 GPT-5、Claude、Gemini、Grok 或本地模型。您甚至可以在聊天中途切换模型,而不会影响技能的正常使用。TypingMind 使用您自己的 API 密钥,因此您直接向提供商付费,而不是按席位订阅;您的技能和聊天记录也都保留在您自己的存储空间中。

如何在 TypingMind 中安装 Blender Errors Context?

在 TypingMind 中打开“插件 → 技能 → 从 GitHub 安装”,然后粘贴 https://github.com/Impertio-Studio/Blender-Bonsai-ifcOpenshell-Sverchok-Claude-Skill-Package/tree/main/skills/blender/errors/blender-errors-context。TypingMind 会读取其中的 SKILL.md,打包相关文件,并将其安装为技能,供您在各个聊天中按需启用。

哪些 AI 模型可以使用 Blender Errors Context?

您在 TypingMind 中连接的任何模型都可以。AI 技能采用纯 Markdown 指令,而非特定提供商专用的代码,因此 GPT、Claude、Gemini、Grok 和本地模型都能在请求匹配时加载此技能。

Blender Errors Context 可以搭配多少个 AI 模型使用?

数量不限。只要模型支持技能,您就可以将它与 Blender Errors Context 搭配使用。GPT、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 等模型都可以通过您自己的 API 密钥接入 TypingMind。

Blender Errors Context AI 技能免费吗?

是的。Impertio-Studio 已在 GitHub 上根据 MIT 许可证发布了该技能。您只需向自己的 AI 提供商支付所用 Token 的费用。

什么是 AI 技能?

AI 技能是一组可复用的指令,用于教会 AI 模型完成某项特定任务。它遵循开放的 Agent Skills 格式:包含名称和描述的 SKILL.md 文件,以及模型可能需要的脚本、模板或参考文件。模型仅在您的请求与技能匹配时才会读取这些指令,因此已安装的技能在使用前不会产生任何费用。

AI 技能与插件或 MCP 服务器有何不同?

插件或 MCP 服务器为模型提供可调用的新工具,也就是在某处运行并返回结果的代码。AI 技能则为模型提供知识和流程:如何处理任务、遵循哪些步骤,以及怎样的输出才算优质。技能采用纯 Markdown 格式,因此不需要服务器、API 密钥或运行时环境,并且适用于任何模型。

查看全部

立即创建您自己的 AI 工作区

订阅我们的电子简报,获取新功能和后续赠奖活动的通知 👇