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 add_bones_bone(self, context, rig): # Add bones then set their defaults root = self.get_root(rig) prev_bones = self.get_prev_bones(rig) bone = rig.data.edit_bones.new('Bone') bone.parent = root bone.translate( Vector( utils.multiply_list( Get.cursor(context).location, rig.matrix_world.inverted().to_scale( ), # Get the transforms for the unscaled rig )) - rig.matrix_world.to_translation()) # Use the original bone size (unscaled by the rig) bone.tail = bone.head + Vector( utils.multiply_list( Vector((0, 0, 0.1)), rig.matrix_world.inverted().to_scale(), )) - rig.matrix_world.to_translation() bone = str(bone.name) # Switch back to Pose mode and setup pose bones Set.mode(context, 'POSE', rig) bone = rig.data.bones[bone] rig.data.bones.active = bone Set.select(bone)
def returnToArmature(context, widget): bone = fromWidgetFindBone(widget) armature = bone.id_data # Unhide collection if it was hidden in a previous run if widget.users_collection: # Try to use the widget's collection collection = widget.users_collection[0] else: # otherwise use default collection = get_collection(context) Set.visible(context, collection) Set.mode(context, 'OBJECT', widget) # collection = get_collection(context) if [x for x in armature.users_collection if x != collection]: # Don't hide the active collection collection.hide_viewport = True "New version doesn't have this" # get_collection_view_layer(collection).hide_viewport = True if getattr(context.space_data, 'local_view', None): bpy.ops.view3d.localview() Set.active(context, armature) Set.select(armature, True) Set.mode(context, 'POSE', armature) # Set.select(bone, True) # Set.active(context, bone) armature.data.bones[bone.name].select = True armature.data.bones.active = armature.data.bones[bone.name]
def editWidget(context, active_bone): widget = active_bone.custom_shape armature = active_bone.id_data Set.mode(context, 'OBJECT', armature) Set.select(armature, False) ''' # 2.7 if context.space_data.lock_camera_and_layers == False : visibleLayers = numpy.array(bpy.context.space_data.layers)+widget.layers-armature.layers bpy.context.space_data.layers = visibleLayers.tolist() else : visibleLayers = numpy.array(bpy.context.scene.layers)+widget.layers-armature.layers bpy.context.scene.layers = visibleLayers.tolist() ''' "Commented because the new version only uses get_collection" if widget.users_collection: collection = widget.users_collection[0] else: collection = get_collection(context) collection.objects.link(widget) Set.in_scene(context, collection) Set.visible(context, collection) "Commented because new version uses operator" # get_collection_view_layer(collection).hide_viewport = False if getattr(context.space_data, 'local_view', None): bpy.ops.view3d.localview() # select object and make it active Set.select(widget, True) Set.active(context, widget) Set.mode(context, 'EDIT', widget)
def get_prev_bones(rig): prev_bones = [] for b in rig.data.bones: if b.select: prev_bones.append(b.name) Set.select(b, False) Set.select(rig.data.edit_bones[b.name], False) return prev_bones
def invoke(self, context, event): target = context.active_target if event.alt: Set.select(target, False) elif event.shift: Set.active_select(context, target, isolate=False) elif event.ctrl: Set.active_select(context, target, isolate=True) else: return self.execute(context) return {'FINISHED'}
def add_bones_mch(self, context, rig, mch_parent=False): # Add bones then set their defaults root = self.get_root(rig) prev_bones = self.get_prev_bones(rig) pose_bones = [] # Get MCH Prefix parent_name = context.scene.mch_bone if parent_name == "": parent_name = "MCH-parent_" for bone_name in prev_bones: prev = rig.data.edit_bones[bone_name] # Replace bone prefixes with MCH instead of inserting keeping both name = parent_name + (prev.name.replace("DEF-", "", 1)).replace( "CTRL-", "", 1) bone = rig.data.edit_bones.new(name) pose_bones.append([bone.name, prev.name]) self.reset(bone, prev) bone.use_deform = False bone.use_connect = prev.use_connect bone.parent = prev.parent prev.use_connect = False prev.parent = bone # prev.select = False # prev.hide = True if not mch_parent: for c in prev.children: c.parent = bone Set.select(bone, False) # Switch back to Pose mode and setup pose bones Set.mode(context, 'POSE', rig) for bone, prev in pose_bones: bone = rig.pose.bones[bone] prev = rig.pose.bones[prev] rig.data.bones.active = bone.bone # self.widget(bone, 'Box') ... # Retarget drivers if not mch_parent: for tar in self.mch_driver_targets: if (tar.id is rig) and (tar.bone_target == prev.name): tar.bone_target = bone.name
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 pose_mch(pbone): Set.select(bone, False) Set.select(pbone, True) rig.data.bones.active = pbone.bone mats = (pbone.matrix.copy(), bone.matrix.copy()) (bone.matrix, pbone.matrix) = mats pbone.rotation_mode = bone.rotation_mode pbone.lock_location = bone.lock_location pbone.lock_rotation = bone.lock_rotation pbone.lock_rotation_w = bone.lock_rotation_w pbone.lock_rotations_4d = bone.lock_rotations_4d pbone.lock_scale = (True, False, True) pbone.custom_shape_transform = bone if not pbone.custom_shape: self.bone_widgets['mch'].append(pbone) con = bone.constraints.new('COPY_ROTATION') con.target = rig con.subtarget = pbone.name con = bone.constraints.new('COPY_SCALE') con.target = rig con.subtarget = pbone.name con.use_x = con.use_z = False
def execute(self, context): if (self.type == 'IN_OBJECT'): rigs = set() for b in context.selected_pose_bones: rigs.add(b.id_data) for rig in rigs: for b in rig.data.bones: if Is.visible(context, b) and (not b.hide_select): Set.select(b, True) elif not self.extend: Set.select(b, False) return {'FINISHED'} elif (self.type == 'PSEUDO_LAYERS'): rigs = dict() for b in context.selected_pose_bones: rig = b.id_data if rig not in rigs: rigs[rig] = list() try: selected_layers = eval(b.layers_extra) rigs[rig].extend(selected_layers) rigs[rig] = list(set(rigs[rig])) except: pass for (rig, selected_layers) in rigs.items(): visible_layers = [ i for i, l in enumerate(rig.data.layers_extra.layers) if l.visible ] for b in rig.pose.bones: try: bone_layers = eval(b.layers_extra) except: continue if Is.visible(context, b): for b_layer in bone_layers: if (b_layer in selected_layers) and ( b_layer in visible_layers): Set.select(b, True) break else: if not self.extend: Set.select(b, False) elif not self.extend: Set.select(b, False) return {'FINISHED'} if self.type == 'GROUP': active_group = set() for b in context.selected_pose_bones: rig = b.id_data if (rig not in active_group) and b.bone_group: rig.pose.bone_groups.active = b.bone_group active_group.add(rig) try: return bpy.ops.pose.select_grouped(type=self.type, extend=self.extend) except RuntimeError as ex: self.report({'ERROR'}, str(ex).split('Error: ', 1)[-1]) return {'CANCELLED'}
def convert(self, context, obj): scn = context.scene Set.active_select(context, obj, isolate=True) coll_instanced = False # Whether or not to instance collection in full macro head = self.head group = obj.name + '-Mannequin' coll = bpy.data.collections.get(group) if coll: # Regenerating mannequin coll_instanced = True for ob in coll.objects.values(): if Is.mesh(ob) and ob.DazMannequin: bpy.data.objects.remove(ob) else: coll = bpy.data.collections.new(group) scn.collection.children.link(coll) # "temporarily" unhide collection if hidden in_view = Is.in_view(context, coll) if not in_view: Set.visible(context, coll, view_layer=True) visible = Is.visible(context, coll) if not visible: Set.visible(context, coll) # Add mannequin objects for current mesh self.generate(context, obj, obj.parent, coll) if self.macro: has_mann = False for ob in coll.objects.values(): if Is.mesh(ob): Set.select(ob) has_mann = True if has_mann: bpy.ops.object.data_transfer_mannequin_preset() # if obj.data.materials: # bpy.ops.object.data_transfer_materials() # Hide the collection and create an instancer of it # if coll: # # Set.visible(context, obj, value=False) # Set.visible(context, coll, value=False, view_layer=True) # if not coll_instanced: # inst = New.object(context, name=coll.name) # inst.instance_type = 'COLLECTION' # inst.instance_collection = coll # Set.empty_size(inst, 0) # return inst for ob in coll.objects.values(): Set.select(ob, value=False) if not visible: Set.visible(context, coll, False) if not in_view: Set.visible(context, coll, False, view_layer=True) return obj