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.5" },
"host": { "protocol": 1, "range": "^0.4.6" },
"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
2 changes: 1 addition & 1 deletion integrations/blender/host/opencode_link/addon.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ def register():

def _start_offer():
# A Blender that OpenCode Link started to render (render.render_animation) is never offered.
if os.environ.get("OPENCODE_LINK_ROLE") == "render":
if os.environ.get("OPENCODE_LINK_ROLE") in ("render", "verify"): # a background Blender of blender_render or verify
return None
if _session is not None:
_session.start(preferences())
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.5"
version = "0.4.6"
name = "OpenCode Link"
tagline = "Lets OpenCode work on this Blender session"
maintainer = "NeuralNomads"
Expand Down
114 changes: 112 additions & 2 deletions integrations/blender/host/opencode_link/hints.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,126 @@ def _operator_poll(error, text, code, filename):
seen[member] = value.type
else:
seen[member] = getattr(value, "name", None) or type(value).__name__
hint = {"operator": idname, "poll": m.group(3).strip()[:300], "context": seen,
"give_context": "with bpy.context.temp_override(window=..., area=..., region=..., id=..., active_object=...)"}
hint = {"operator": idname, "poll": m.group(3).strip()[:300], "context": seen}
try:
rna = getattr(getattr(bpy.ops, m.group(1)), m.group(2)).get_rna_type()
hint["description"] = (rna.description or "")[:300]
except Exception: # noqa: BLE001
pass
hint.update(context_help(m.group(1), m.group(2)))
return hint


# -- what would let a refused operator run: its poll() tried, the operator never executed ---------------------------
TRIES = 400 # poll() calls at most per refused operator
_ROOTS = ("active_object", "scene", "view_layer")


def context_help(module, name):
"""For an operator whose poll refuses the current context: the operators of its group whose poll passes now,
and the context members that make its poll pass, found by trying, with temp_override, the data reachable from
the active object, the scene and the view layer (a member is named after the property that leads to it, or after
a collection's item type), then the screen's areas. Only poll() runs."""
out = {}
try:
group = getattr(bpy.ops, module)
op = getattr(group, name)
except Exception: # noqa: BLE001
return out
passing = []
for other in sorted(dir(group)):
if other != name and _polls(getattr(group, other, None)):
passing.append("%s.%s" % (module, other))
if passing:
out["same_group_passing"] = passing[:12]
found, tries = [], [0]

def attempt(override, shown):
if tries[0] >= TRIES or len(found) >= 4:
return
tries[0] += 1
try:
with bpy.context.temp_override(**override):
if op.poll():
found.append(shown)
except Exception: # noqa: BLE001 - a member this context does not take
pass

for member, value, path in _candidates():
attempt({member: value}, {member: path})
window = getattr(bpy.context, "window", None)
if not found and window is not None:
for area in window.screen.areas:
region = next((r for r in area.regions if r.type == "WINDOW"), None)
attempt({"window": window, "area": area, "region": region},
{"area": "the %s area of bpy.context.window.screen, with its WINDOW region" % area.type})
if found:
out["passes_with"] = [{"temp_override": shown} for shown in found]
out["note"] = "found by trying poll() only; the operator did not run"
else:
out["give_context"] = "with bpy.context.temp_override(window=..., area=..., region=..., id=..., active_object=...)"
return out


def _polls(op):
try:
return bool(op.poll())
except Exception: # noqa: BLE001
return False


def _snake(identifier):
return re.sub(r"(?<=[a-z0-9])(?=[A-Z])", "_", identifier).lower()


def _candidates():
"""(member, value, Python path) for the data two steps from the context's roots: pointers named after their
property, collection items after the collection's item type (modifiers -> modifier), IDs also as id."""
seen = set()
for root in _ROOTS:
value = getattr(bpy.context, root, None)
if value is None:
continue
base = "bpy.context.%s" % root
if isinstance(value, bpy.types.ID):
yield "id", value, base
for member, item, path in _children(value, base):
key = (member, item.as_pointer() if hasattr(item, "as_pointer") else id(item))
if key not in seen:
seen.add(key)
yield member, item, path
for member2, item2, path2 in _children(item, path):
key = (member2, item2.as_pointer() if hasattr(item2, "as_pointer") else id(item2))
if key not in seen:
seen.add(key)
yield member2, item2, path2


def _children(struct, path):
rna = getattr(struct, "bl_rna", None)
if rna is None or isinstance(struct, bpy.types.PropertyGroup):
return
for p in rna.properties:
if p.identifier == "rna_type" or p.type not in ("POINTER", "COLLECTION"):
continue
try:
value = getattr(struct, p.identifier)
except Exception: # noqa: BLE001
continue
if value is None:
continue
if p.type == "POINTER":
yield p.identifier, value, "%s.%s" % (path, p.identifier)
else:
member = _snake(p.fixed_type.identifier)
for index, item in enumerate(value):
if index >= 8:
break
key = getattr(item, "name", None)
shown = "%s.%s[%r]" % (path, p.identifier, key) if key else "%s.%s[%d]" % (path, p.identifier, index)
yield member, item, shown


def _operator_arguments(error, text, code, filename):
idname, rna = _operator_rna(error)
if rna is None or not isinstance(error, (TypeError, ValueError)):
Expand Down
2 changes: 1 addition & 1 deletion integrations/blender/host/ops.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"addon": "opencode_link",
"version": "0.4.5",
"version": "0.4.6",
"protocol": 1,
"method": "apply",
"wire": "params.operations: [{op, args}] with every op below (an edit batch); unknown ops and fields are refused",
Expand Down
Loading
Loading