def execute(self, context): active = Get.active(context) active_select = Is.selected(active) selected = Get.selected(context) is_pose = bool(context.mode == 'POSE') arg = dict(only_selected=bool(selected)) if is_pose: clear = bpy.ops.pose.paths_clear # Operator only runs on active rig, so repeat for all in pose mode if selected: obs = {b.id_data for b in selected} else: obs = {ob for ob in Get.objects(context) if ob.mode == 'POSE'} for ob in obs: Set.active(context, ob) clear(**arg) else: Set.active(context, active) Set.select(active, active_select) elif bpy.ops.object.paths_clear.poll(context.copy()): bpy.ops.object.paths_clear(**arg) return {'FINISHED'}
def execute(self, context): selection = Get.selected(context) if not selection: selection = [Get.active(context)] for src in selection: if Is.posebone(src): mp = src.id_data.pose.animation_visualization.motion_path else: mp = src.animation_visualization.motion_path mp.type = self.type return {'FINISHED'}
def active(context, target): """Set target as active scene object or bone""" objects = Get.objects(context) # Remember previous active previous = Get.active(context) selected = Is.selected(target) # Set the active if Is.object(target): obj = target elif Is.posebone(target): obj = target.id_data obj.data.bones.active = obj.data.bones.get(target.name) elif isinstance(target, bpy.types.Armature): obj = Get.rig(context, target) elif Is.bone(target): obj = Get.rig(context, target) bones = target.id_data.bones bones.active = bones.get(target.name) elif Is.editbone(target): obj = Get.rig(context, target) if obj: in_edit = (obj.mode == 'EDIT') else: in_edit = (context.mode == 'EDIT_ARMATURE') if in_edit: bones = target.id_data.edit_bones bones.active = bones.get(target.name) elif target is None: obj = None # debug("Set.active() has None as the target") else: assert None, ("Set.active() can't use the provided target", target) if (target and Is.selected(target) != selected): # When setting a bone as active in a rig, it gets selected as well. Set.select(target, selected) objects.active = obj return previous
def execute(self, context): active = Get.active(context) mode = context.mode pose = list() for rig in context.selected_objects: (rig, meta) = self.poll_parse(context, rig) if None in (rig, meta): continue rigify_to_meta(rig, meta) pose.append((meta, rig)) else: if mode == 'POSE': Set.mode(context, 'OBJECT') for (meta, rig) in pose: Set.select(rig, False) Set.select(meta, True) if rig == active: Set.active(context, meta) if mode == 'POSE': Set.mode(context, 'POSE') return {'FINISHED'}
def execute(self, context): scn = context.scene active = Get.active(context) selected = Get.selected(context) is_pose = bool(context.mode == 'POSE') if not is_pose: self.use_tails = False mode = ('HEADS', 'TAILS')[self.use_tails] # Use the line thickness of the active item, across the selection if getattr(active, 'motion_path', None): line = active.motion_path.line_thickness else: line = 1 colors = dict() types = dict() for src in Get.selected(context): mp = src.motion_path if not mp: continue if mp.use_custom_color: colors[src] = mp.color if Is.posebone(src): display = src.id_data.pose.animation_visualization.motion_path else: display = src.animation_visualization.motion_path types[src] = display.type # Get the frame range to bake motion paths in motion = utils.prefs(__package__).motion if self.use_start_end: start = self.start_frame end = self.end_frame elif (motion.use_relative_range) or (scn.use_preview_range): start = scn.frame_preview_start end = scn.frame_preview_end fc = scn.frame_current fb = motion.frame_before fa = motion.frame_after if not (scn.use_preview_range) or (abs(end - start) > 100 > (fb + fa)): # If the preview range is too high, just default to nearby start = fc - fb end = fc + fa else: # if (active): # # Use the active object's motion path's in_range distance # if (Is.posebone(active)): # mp = active.id_data.pose.animation_visualization.motion_path # else: # mp = active.animation_visualization.motion_path # fb = mp.frame_before # fa = mp.frame_after # if (fb < 25): fb = 25 # if (fa < 25): fa = 25 # start = scn.frame_current - fb # end = scn.frame_current + fa start = scn.frame_start end = scn.frame_end fc = scn.frame_current if 150 < abs(end - start): start = fc - 50 end = fc + 50 # Create the motion paths args = dict(start_frame=start, end_frame=end + 1) if is_pose: op = bpy.ops.pose args['bake_location'] = mode # Operator only runs on active rig, so repeat for all in pose mode obs = {b.id_data for b in selected} for ob in obs: Set.active(context, ob) op.paths_clear(only_selected=True) op.paths_calculate(**args) else: Set.active(context, active) else: op = bpy.ops.object op.paths_clear(only_selected=True) op.paths_calculate(**args) for src in selected: mp = src.motion_path if not mp: continue mp.line_thickness = line color = colors.get(src) if color: mp.color = color if Is.posebone(src): display = src.id_data.pose.animation_visualization.motion_path else: display = src.animation_visualization.motion_path display.type = types.get(src, 'CURRENT_FRAME') # Set to use the frame hider instead of ever displaying all points # if is_pose: # src.id_data.pose.animation_visualization. \ # motion_path.type = 'CURRENT_FRAME' # else: # src.animation_visualization. \ # motion_path.type = 'CURRENT_FRAME' # scn.frame_set(scn.frame_current) return {'FINISHED'}