Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- Copyright (c) [2/25/24] [Dieton]
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated documentation files (the "Software"), to deal
- in the Software without restriction, including without limitation the rights
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the Software is
- furnished to do so, subject to the following conditions:
- The above copyright notice and this permission notice shall be included in all
- copies or substantial portions of the Software.
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- SOFTWARE.
- Instructions
- 1. Make sure to add "Shapekey_Name_List.txt" to code
- 2. Make sure Armature Modifier Name is Armature
- 3. Select object mesh in object mode
- 4. press play
- 5. done
- """
- import bpy
- def read_names_from_file(file_path):
- names = []
- with open(file_path, 'r') as file:
- for line in file:
- names.append(line.strip())
- return names
- def apply_shape_keys_from_file():
- # Get the active object
- active_object = bpy.context.active_object
- # Check if an object is selected and is in Object mode
- if active_object and active_object.type == 'MESH' and bpy.context.mode == 'OBJECT':
- # Ensure the mesh has an armature modifier
- armature_modifier = active_object.modifiers.get("Armature")
- if not armature_modifier:
- print("Error: Please select a mesh with an Armature modifier.")
- return
- # Set the file path to the text file containing names (replace with your file path)
- file_path = "Shapekey_Name_List.txt"
- # Read names from the file
- names = read_names_from_file(file_path)
- # Set the frame range based on your animation
- start_frame = bpy.context.scene.frame_start
- end_frame = bpy.context.scene.frame_end
- # Iterate over each frame
- for frame in range(start_frame, end_frame + 1):
- # Set the current frame
- bpy.context.scene.frame_set(frame)
- # Apply the armature modifier as a shape key
- bpy.ops.object.modifier_apply_as_shapekey(keep_modifier=True, modifier="Armature")
- # Assign a name from the list to the new shape key
- shape_key_name = names[frame % len(names)]
- active_object.data.shape_keys.key_blocks[-1].name = shape_key_name
- print("Shape keys applied and named from the file.")
- else:
- print("Error: Please select a mesh object in Object mode.")
- # Call the function to apply shape keys and assign names
- apply_shape_keys_from_file()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement