Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- Copyright (c) [2/22/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.
- """
- import bpy
- def create_matching_shape_keys(obj_list):
- source_object = None
- target_object = None
- # Iterate through the selected objects
- for obj in obj_list:
- if obj.data.shape_keys:
- # If the object has shape keys, assign it as the source
- source_object = obj
- else:
- # If the object does not have shape keys, assign it as the target
- target_object = obj
- # Check if both source and target objects are found
- if source_object and target_object:
- print("Source Object: {}".format(source_object.name))
- print("Target Object: {}".format(target_object.name))
- # Check if source_object has shape keys
- if source_object.data.shape_keys is None:
- print("Error: The source object should have shape keys.")
- return
- # Create matching shape keys in the target object
- for shape_key_source in source_object.data.shape_keys.key_blocks:
- shape_key_target = target_object.shape_key_add(name=shape_key_source.name, from_mix=False)
- print("Shape keys created on '{0}' matching '{1}'.".format(target_object.name, source_object.name))
- else:
- print("Error: One object should have shape keys, and the other should not.")
- # Get the selected objects
- selected_objects = bpy.context.selected_objects
- # Ensure two objects are selected
- if len(selected_objects) == 2:
- # Call the function to create matching shape keys
- create_matching_shape_keys(selected_objects)
- else:
- print("Error: Please select exactly two objects.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement