def poll(cls, context): space = getattr(context, 'space', None) if Is.gpencil(context.object): if space and space.grease_pencil == context.object.data: return False return True
def draw(self, context, space): layout = self.layout # .column(align=True) layout.context_pointer_set('space', space) r1 = r2 = None if space.grease_pencil or Is.gpencil(context.object): row = layout.column(align=True) if space.grease_pencil: r1 = row.split(align=True, factor=0.60) if Is.gpencil(context.object): r2 = row.split(align=True, factor=0.60) if r1: gpd = space.grease_pencil r1.context_pointer_set('gpencil', gpd) r1.operator('zpy.gp_from_annotation', text="To Grease Pencil", icon='OUTLINER_OB_GREASEPENCIL') r1.operator_menu_enum('zpy.toggle_gp_space', 'space', text=get_active(gpd), icon='OUTLINER_DATA_GREASEPENCIL') if r2: gpd = context.object.data text = get_active(gpd) r2.context_pointer_set('gpencil', gpd) r2.operator('zpy.annotation_from_gp', text="From Grease Pencil", icon='OUTLINER_DATA_GREASEPENCIL') r2.operator_menu_enum('zpy.toggle_gp_space', 'space', text=get_active(gpd), icon='OBJECT_DATA')
def scan_actions(context, sub, selected): scn = context.scene fc = (int(scn.frame_current_final), scn.frame_current_final)[sub] frames = list() for obj in selected: if Is.gpencil(obj): for layer in obj.data.layers: for frame in layer.frames: frames.append(frame.frame_number) for obj in Get.objects_nla(context): # Poll object if pose(context): if not pose(obj): continue elif selected: bones = [ f'pose.bones[\"{b.name}\"]' for b in Get.selected_pose_bones(context, src=obj) ] if not bones: continue else: bones = list() else: if (selected and obj not in selected): continue else: bones = list() for anim in Get.animation_datas(obj): if (not anim.action): continue if anim.use_tweak_mode: for s in Get.strips(anim.id_data): if s.action == anim.action: strip = s if s.active: break # Get loop ends cycle = list() afe = strip.action_frame_end fel = fer = Get.frame_from_strip(context, strip, afe) while fel < strip.frame_end: offset = (fer - strip.frame_start) cycle.append(offset) fel += abs(offset) # If offset becomes negative, it "should" create an infinite loop # abs() forces positive, which "should" prevent loop else: strip = None for fcurve in anim.action.fcurves: path = fcurve.data_path if bones: # Bones are selected, so verify this fcurve if for one of them for bpath in bones: if path.startswith(bpath): break else: continue elif path.startswith('pose.bones[\"'): try: eval(repr(obj) + '.' + path) # Validate path bpath = path.split('\"]', 1)[0] + '\"]' bone = eval(repr(obj) + '.' + bpath) if not Is.visible(context, bone): continue except: # curve points to a removed bone or something continue scan_fcurve(context, sub, fcurve, frames, strip=strip) return sorted(set(frames))