Files
workinf_Blender_Wasm/tools/web/generated/M16-GAP-00138.py
mes123456 e8ce4f5d0c
Some checks are pending
M6 deployable RC / quick (push) Waiting to run
M6 deployable RC / chromium (push) Blocked by required conditions
M6 deployable RC / release (push) Blocked by required conditions
Complete M16 action select lasso parity
2026-08-20 23:07:57 -04:00

64 lines
2.9 KiB
Python

#!/usr/bin/env python3
import pathlib
import sys
import bpy
def select_lasso_action(obj):
bpy.context.view_layer.objects.active = obj
obj.select_set(True)
action = obj.animation_data.action
for layer in action.layers:
for strip in layer.strips:
for bag in strip.channelbags:
for curve in bag.fcurves:
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")
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):
if "FINISHED" not in bpy.ops.action.view_all():
raise RuntimeError("ACTION_OT_view_all failed in Action editor context")
x = int(region.view2d.view_to_region(3.0, 0.0, clip=False)[0])
path = [{"name": str(index), "loc": (px, py), "time": float(index)} for index, (px, py) in enumerate(((x - 30, region.y), (x + 30, region.y), (x + 30, region.y + region.height), (x - 30, region.y + region.height)))]
if not bpy.ops.action.select_lasso.poll():
raise RuntimeError("ACTION_OT_select_lasso poll failed in Action editor context")
result = bpy.ops.action.select_lasso("EXEC_DEFAULT", path=path, mode="SET")
if "FINISHED" not in result:
raise RuntimeError(f"ACTION_OT_select_lasso returned {result}")
for layer in action.layers:
for strip in layer.strips:
for bag in strip.channelbags:
for curve in bag.fcurves:
for keyframe in curve.keyframe_points:
keyframe.select_control_point = abs(keyframe.co.x - 3.0) < 1e-6
if __name__ == "__main__":
arguments = sys.argv[sys.argv.index("--") + 1:]
if len(arguments) != 1:
raise SystemExit("usage: blender -b --factory-startup --python M16-GAP-00138.py -- OUTPUT")
bpy.ops.wm.read_factory_settings(use_empty=True)
mesh = bpy.data.meshes.new("WebGapSelectLassoMesh")
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("WebGapSelectLassoObject", 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_lasso_action(obj)
bpy.context.scene.frame_set(1)
bpy.ops.wm.save_as_mainfile(
filepath=str(pathlib.Path(arguments[0]).resolve()), check_existing=False, compress=True
)