Advertisement
Dieton

Blend_Shape_Text_File_Names_To_Shape_Keys.py

Mar 3rd, 2024 (edited)
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.10 KB | None | 0 0
  1. """
  2. Copyright (c) [2/25/24] [Dieton]
  3.  
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10.  
  11. The above copyright notice and this permission notice shall be included in all
  12. copies or substantial portions of the Software.
  13.  
  14. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  20. SOFTWARE.
  21. """
  22. import bpy
  23.  
  24. def create_shape_keys_from_file(file_path):
  25.     # Get the active object
  26.     active_object = bpy.context.active_object
  27.  
  28.     # Check if an object is selected
  29.     if active_object:
  30.         # Open the file in read mode
  31.         with open(file_path, 'r') as file:
  32.             # Read shape key names from the file
  33.             shape_key_names = [line.strip() for line in file.readlines()]
  34.  
  35.         # Create shape keys based on the names
  36.         for name in shape_key_names:
  37.             bpy.ops.object.shape_key_add(from_mix=False)
  38.             shape_key = active_object.data.shape_keys.key_blocks[-1]
  39.             shape_key.name = name
  40.             shape_key.value = 0  # Set the initial value to 0
  41.        
  42.         print(f"Shape keys created based on names from: {file_path}")
  43.     else:
  44.         print("Error: No object selected.")
  45.  
  46. # Set the file path containing shape key names
  47. file_path = "shape_key_names.txt"
  48.  
  49. # Call the function to create shape keys based on the names from the file
  50. create_shape_keys_from_file(file_path)
  51.  
Tags: blender
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement