-
Notifications
You must be signed in to change notification settings - Fork 11
Open
Description
I hate blender addon system API. I hate it.
batch *.anim import script. by DeepSeek.
Because importing anims overwrite the same action.
`
import os
import bpy
Function to find the armature in the scene
def find_armature():
for obj in bpy.context.scene.objects:
if obj.type == 'ARMATURE':
return obj
return None
Function to clone and rename the current action
def clone_and_rename_action(new_name):
armature = find_armature()
if not armature or not armature.animation_data or not armature.animation_data.action:
print("No armature or active action found.")
return
# Get the current action
current_action = armature.animation_data.action
# Clone the action
new_action = current_action.copy()
new_action.name = new_name
# Assign the new action to the armature
armature.animation_data.action = new_action
print(f"Cloned and renamed action to '{new_name}'.")
Function to process all .motion files in a folder
def process_motion_folder(folder_path):
if not os.path.isdir(folder_path):
print(f"Directory does not exist: {folder_path}")
return
motion_files = [f for f in os.listdir(folder_path) if f.endswith('.motion')]
if not motion_files:
print("No .motion files found in the directory.")
return
for motion_file in motion_files:
file_path = os.path.join(folder_path, motion_file)
print(f"Processing: {file_path}")
# Use the existing operator to import the motion file
bpy.ops.haydee_importer.motion(filepath=file_path)
# Clone and rename the resulting action
action_name = os.path.splitext(motion_file)[0]
clone_and_rename_action(action_name)
# Clear the current action to prepare for the next file
armature = find_armature()
if armature and armature.animation_data:
armature.animation_data.action = None
print("Finished processing all .motion files.")
Main script execution
if name == "main":
folder_path = "C:/path/to/your/motion/files" # Replace with your folder path
process_motion_folder(folder_path)
`
Metadata
Metadata
Assignees
Labels
No labels