Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion catalog.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"fr": "Lire et modifier la scène ouverte dans Blender grâce à l'extension OpenCode Link : changements typés en un pas d'annulation, inspection du Blender lancé, rendus de vérification et en arrière-plan."
},
"app": { "name": "Blender", "versions": ">=5.3" },
"host": { "protocol": 1, "range": "^0.4.3" },
"host": { "protocol": 1, "range": "^0.4.4" },
"docs": "https://github.com/NeuralNomadsAI/opencode-integrations/blob/main/integrations/blender/plugin/README.md",
"status": "preview",
"sources": { "git": ["github:NeuralNomadsAI/opencode-integrations#main::path:integrations/blender/plugin"] }
Expand Down
19 changes: 19 additions & 0 deletions integrations/blender/host/opencode_link/blender_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
import os
import queue
import secrets
import tempfile
import threading
import time

import bpy

from . import hints, op_watch
from .process import state as process_state
from .wire import HostFailure
from .native_refs import NativeRefs
Expand Down Expand Up @@ -413,6 +415,7 @@ def _with_window(self, fn):

def undo_push(self, message):
self._with_window(lambda: bpy.ops.ed.undo_push(message=message[:63]))
op_watch.undo_stack_made()

def undo(self):
epoch = self.script_epoch()
Expand Down Expand Up @@ -544,6 +547,22 @@ def created_refs(self, op, result):
def exec_namespace(self):
return {"bpy": bpy, "__name__": "__opencode_execute__"}

@staticmethod
def watch_operators():
return op_watch.watching()

@staticmethod
def explain(error, code, filename):
return hints.explain(error, code, filename)

@staticmethod
def process():
"""This Blender's process and the folder its crash report goes to (<file name>.crash.txt, or
blender.crash.txt for an unsaved file): the parent of its session temporary folder."""
session = bpy.app.tempdir
return {"pid": os.getpid(),
"temp_dir": os.path.dirname(os.path.normpath(session)) if session else tempfile.gettempdir()}


# UI datablocks (windows, screens, workspaces) are not the document's content.
_UI_DATA = frozenset(("window_managers", "screens", "workspaces"))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
schema_version = "1.0.0"

id = "opencode_link"
version = "0.4.3"
version = "0.4.4"
name = "OpenCode Link"
tagline = "Lets OpenCode work on this Blender session"
maintainer = "NeuralNomads"
Expand Down
20 changes: 19 additions & 1 deletion integrations/blender/host/opencode_link/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,8 @@ def _hello(self, params):
document = self.app.document()
if document:
hello["document"] = document
if hasattr(self.app, "process"):
hello["process"] = self.app.process() # the plugin says where the crash report is if Blender closes
return hello

def _reload(self, params):
Expand Down Expand Up @@ -908,14 +910,28 @@ def _execute_code(self, params):
# modified: inspections and runs after a save leave the file saved; a change is reported, never undone.
read_only = params.get("read_only") is True
rotations = self.app.rotation_snapshot() if hasattr(self.app, "rotation_snapshot") else None
notes, hint = [], []

def run():
exec(compile(code, filename or "<opencode execute_code>", "exec"), namespace) # noqa: S102 - the dangerous method
# Operator calls watched (guards, the failing operator named); a failure on Blender's API explained
# by what is valid there, read before the failed run is undone.
watch = self.app.watch_operators() if hasattr(self.app, "watch_operators") else contextlib.nullcontext()
with watch as watched:
try:
exec(compile(code, filename or "<opencode execute_code>", "exec"), namespace) # noqa: S102 - the dangerous method
except Exception as error:
found = self.app.explain(error, code, filename) if hasattr(self.app, "explain") else None
if found:
hint.append(found)
raise
finally:
notes.extend(getattr(watched, "notes", None) or [])
check = namespace.get("check_is_finished")
return check if callable(check) else None

done = self._guarded(run, "code", barrier=not read_only)
warnings = self.app.rotation_warnings(rotations) if rotations is not None else []
warnings.extend(notes)
if read_only and done.changed:
warnings.append("OpenCode: this read_only run changed the document; no undo step groups or undoes it.")

Expand All @@ -935,6 +951,8 @@ def finish(deferred=None, deferred_error=None):
output["warnings"] = warnings
if done.error:
output.update(message=done.error, traceback=done.trace)
if hint:
output["hint"] = hint[0]
if done.changed:
output["restored"] = done.restored
if self.residue:
Expand Down
Loading
Loading