1 # SPDX-License-Identifier: GPL-2.0-or-later
7 def redraw_areas_by_type(window
, area_type
, region_type
='WINDOW'):
8 """Redraw `window`'s areas matching the given `area_type` and optionnal `region_type`."""
9 for area
in window
.screen
.areas
:
10 if area
.type == area_type
:
11 for region
in area
.regions
:
12 if region
.type == region_type
:
16 def redraw_all_areas_by_type(context
, area_type
, region_type
='WINDOW'):
17 """Redraw areas in all windows matching the given `area_type` and optionnal `region_type`."""
18 for window
in context
.window_manager
.windows
:
19 redraw_areas_by_type(window
, area_type
, region_type
)
22 def get_selected_keyframes(context
):
23 """Get list of selected keyframes for any object in the scene. """
26 for ob
in context
.scene
.objects
:
27 if ob
.type == 'GPENCIL':
28 for gpl
in ob
.data
.layers
:
29 for gpf
in gpl
.frames
:
31 keys
.append(gpf
.frame_number
)
33 elif ob
.animation_data
is not None and ob
.animation_data
.action
is not None:
34 action
= ob
.animation_data
.action
35 for fcu
in action
.fcurves
:
36 for kp
in fcu
.keyframe_points
:
37 if kp
.select_control_point
:
38 keys
.append(int(kp
.co
[0]))
41 unique_keys
= list(set(keys
))
45 def find_collections_recursive(root
, collections
=None):
46 # Initialize the result once
47 if collections
is None:
50 def recurse(parent
, result
):
52 # Look over children at next level
53 for child
in parent
.children
:
54 recurse(child
, result
)
56 recurse(root
, collections
)
61 def get_keyframe_list(scene
, frame_start
, frame_end
):
62 """Get list of frames for any gpencil object in the scene and meshes. """
64 root
= scene
.view_layers
[0].layer_collection
65 collections
= find_collections_recursive(root
)
67 for laycol
in collections
:
68 if laycol
.exclude
is True or laycol
.collection
.hide_render
is True:
70 for ob
in laycol
.collection
.objects
:
73 if ob
.type == 'GPENCIL':
74 for gpl
in ob
.data
.layers
:
77 for gpf
in gpl
.frames
:
78 if frame_start
<= gpf
.frame_number
<= frame_end
:
79 keys
.append(gpf
.frame_number
)
81 # Animation at object level
82 if ob
.animation_data
is not None and ob
.animation_data
.action
is not None:
83 action
= ob
.animation_data
.action
84 for fcu
in action
.fcurves
:
85 for kp
in fcu
.keyframe_points
:
86 if frame_start
<= int(kp
.co
[0]) <= frame_end
:
87 keys
.append(int(kp
.co
[0]))
89 # Animation at datablock level
90 if ob
.type != 'GPENCIL':
92 if data
and data
.animation_data
is not None and data
.animation_data
.action
is not None:
93 action
= data
.animation_data
.action
94 for fcu
in action
.fcurves
:
95 for kp
in fcu
.keyframe_points
:
96 if frame_start
<= int(kp
.co
[0]) <= frame_end
:
97 keys
.append(int(kp
.co
[0]))
100 for m
in scene
.timeline_markers
:
101 if frame_start
<= m
.frame
<= frame_end
and m
.camera
is not None:
102 keys
.append(int(m
.frame
))
104 # If no animation or markers, must add first frame
106 keys
.append(int(frame_start
))
108 unique_keys
= list(set(keys
))