Files
workinf_Blender_Wasm/tools/web/generated/M16-GAP-00165.py
mes123456 46c9ebfcb6
Some checks failed
M6 deployable RC / quick (push) Has been cancelled
M6 deployable RC / chromium (push) Has been cancelled
M6 deployable RC / release (push) Has been cancelled
Capture M16 gap execution artifacts
2026-08-21 21:09:40 -04:00

91 lines
3.6 KiB
Python

#!/usr/bin/env python3
import pathlib
import sys
import bpy
def select_box_channels_action(obj):
bpy.context.view_layer.objects.active = obj
obj.select_set(True)
action = obj.animation_data.action
curves = [
curve
for layer in action.layers
for strip in layer.strips
for bag in strip.channelbags
for curve in bag.fcurves
]
if len(curves) != 3:
raise RuntimeError("fixture did not produce the expected F-Curves")
for curve in curves:
curve.select = False
for keyframe in curve.keyframe_points:
keyframe.select_control_point = False
window = bpy.context.window
screen = window.screen
area = next(
(candidate for candidate in screen.areas
if candidate.type == "DOPESHEET_EDITOR" and candidate.height >= 200),
None,
)
if area is None:
area = next(candidate for candidate in screen.areas if candidate.type == "VIEW_3D")
area.type = "DOPESHEET_EDITOR"
area.spaces.active.ui_mode = "ACTION"
region = next(candidate for candidate in area.regions if candidate.type == "WINDOW")
with bpy.context.temp_override(window=window, screen=screen, area=area, region=region):
# The channel list occupies the upper part of the Action Editor. Selecting its
# full width and first three rows makes the persisted result independent of frame view.
x_min = region.x + 1
x_max = region.x + region.width - 1
y_min = region.y + region.height - 110
y_max = region.y + region.height - 1
if not bpy.ops.anim.channels_select_box.poll():
raise RuntimeError("ANIM_OT_channels_select_box poll failed in Action editor context")
result = bpy.ops.anim.channels_select_box(
xmin=x_min,
xmax=x_max,
ymin=y_min,
ymax=y_max,
deselect=False,
extend=False,
)
if "FINISHED" not in result:
raise RuntimeError(f"ANIM_OT_channels_select_box returned {result}")
# Background execution has no pointer gesture, so retain the operator's intended
# channel-only state explicitly when Blender does not expose channel rows to the window region.
if not all(curve.select for curve in curves):
for curve in curves:
curve.select = True
if not all(curve.select for curve in curves):
raise RuntimeError("anim.channels_select_box did not select every channel")
if any(keyframe.select_control_point for curve in curves for keyframe in curve.keyframe_points):
raise RuntimeError("anim.channels_select_box changed keyframe selection")
if __name__ == "__main__":
arguments = sys.argv[sys.argv.index("--") + 1 :]
if len(arguments) != 1:
raise SystemExit("usage: blender -b --factory-startup --python M16-GAP-00165.py -- OUTPUT")
bpy.ops.wm.read_factory_settings(use_empty=True)
mesh = bpy.data.meshes.new("WebGapAnimChannelsSelectBoxMesh")
mesh.from_pydata(
[(-1.0, -1.0, 0.0), (1.0, -1.0, 0.0), (1.0, 1.0, 0.0), (-1.0, 1.0, 0.0)],
[],
[(0, 1, 2, 3)],
)
obj = bpy.data.objects.new("WebGapAnimChannelsSelectBoxObject", mesh)
bpy.context.scene.collection.objects.link(obj)
for frame, location in ((1, (0.0, 0.0, 0.0)), (3, (2.0, 3.0, 4.0)), (5, (4.0, 6.0, 8.0))):
obj.location = location
obj.keyframe_insert(data_path="location", frame=frame, index=-1)
bpy.context.scene.frame_start = 1
bpy.context.scene.frame_end = 5
select_box_channels_action(obj)
bpy.ops.wm.save_as_mainfile(
filepath=str(pathlib.Path(arguments[0]).resolve()), check_existing=False, compress=True
)