Skip to content

Official Codebase of 3DCodeVerse

Python

blender lint: a join after setting the active object is not warned — the rule's own precondition

gaoypeng919fea7df6a5
diff --git a/harness/codeverse3d/languages/blender/__init__.py b/harness/codeverse3d/languages/blender/__init__.py
index 29a2519b..2f2b414b 100644
--- a/harness/codeverse3d/languages/blender/__init__.py
+++ b/harness/codeverse3d/languages/blender/__init__.py
@@ -241,7 +241,10 @@ def _rules(c: _Collector, source: str, *, target: str, expect_names: bool, expec
if name.endswith("modifier_apply") and not c.has_temp_override:
out.append(_f(W, "bpy.ops.object.modifier_apply needs the object active+selected in OBJECT mode", call.lineno,
"either leave modifiers unapplied (the exporter applies them) or wrap: `with bpy.context.temp_override(object=obj): bpy.ops.object.modifier_apply(modifier=mod.name)`"))
- if name.endswith("bpy.ops.object.join") or name == "bpy.ops.object.join":
+ # the rule's own precondition: a script that sets the active object before joining (the urdf
+ # cookbook's `join_as`, one joined object per link) has done what the warning asks
+ if (name.endswith("bpy.ops.object.join") or name == "bpy.ops.object.join") and not any(
+ t.endswith("view_layer.objects.active") for t, _ in c.attr_stores):
out.append(_f(W, "bpy.ops.object.join needs all parts selected + an active object; the result inherits the ACTIVE object's transform", call.lineno,
"select all, set `bpy.context.view_layer.objects.active = main_obj` (identity transform) before join — or keep parts separate (preferred: named parts)"))
if name.endswith("shade_smooth") and any(k.arg == "use_auto_smooth" for k in call.keywords):
diff --git a/harness/tests/blender_cadquery/test_blender_lint.py b/harness/tests/blender_cadquery/test_blender_lint.py
index d8c5330d..c358d63a 100644
--- a/harness/tests/blender_cadquery/test_blender_lint.py
+++ b/harness/tests/blender_cadquery/test_blender_lint.py
@@ -107,6 +107,13 @@ def test_camera_light_and_render_settings_warn() -> None:
assert any("light_add" in m for m in w) and any("cameras.new" in m for m in w) and any("render settings" in m for m in w)
+def test_a_join_after_setting_the_active_object_is_not_warned() -> None:
+ """The urdf cookbook's `join_as` sets the active object first — what the join warning asks for."""
+ src = ("import bpy\nobjs = [o for o in bpy.data.objects]\nfor o in objs: o.select_set(True)\n"
+ "bpy.context.view_layer.objects.active = objs[0]\nbpy.ops.object.join()\n")
+ assert not any("join" in m for m in _msgs(lint_blender_source(src), Severity.WARN))
+
+
def test_headless_pitfalls() -> None:
src = ("import bpy\nbpy.ops.mesh.primitive_cube_add(scale=(1, 2, 3))\nbpy.ops.object.transform_apply(scale=True)\n"
"bpy.ops.object.modifier_apply(modifier='Bevel')\nbpy.ops.object.join()\nsel = bpy.context.selected_objects\n"