#!/usr/bin/env python # -*- coding: utf-8 -*- """ 版权所有: 深圳时光科技有限公司 联系方式: q.100@qq.com 创建日期: 2024/03/20 """ import os import maya.cmds as cmds def sg_unload_plugin(): """ 卸载当前Maya版本的插件 """ # 获取Maya版本 version = cmds.about(version=True) plugin_name = f"SuperRiggingEditor{version}" # 如果插件已加载,则卸载 if cmds.pluginInfo(plugin_name, query=True, loaded=True): cmds.unloadPlugin(plugin_name) def sg_update_plugin(): """ 更新插件文件 从更新文件夹复制新版本插件到对应的插件目录 """ # 获取更新文件夹路径 sg_path = os.environ.get("SG_PATH") update_folder = os.path.join(sg_path, "plug-ins-update") # 检查更新文件夹是否存在 if os.path.exists(update_folder): # 卸载当前插件 sg_unload_plugin() # 支持的Maya版本列表 versions = ["2018", "2019", "2020", "2022", "2023", "2024"] # 处理每个版本的插件 for version in versions: # 构建路径 update_path = os.path.join(sg_path, "plug-ins-update", version) target_path = os.path.join(sg_path, "plug-ins", version) # 获取需要更新的插件文件列表 if os.path.exists(update_path): plugins = [f for f in os.listdir(update_path) if f.endswith('.mll')] # 更新每个插件 for plugin in plugins: new_file = os.path.join(update_path, plugin) old_file = os.path.join(target_path, plugin) try: # 复制新文件到目标位置 if os.path.exists(new_file): os.replace(old_file, new_file) print(f"{old_file} update succeeded...") os.remove(new_file) except Exception as e: print(f"{old_file} update failed: {str(e)}") # 删除空的更新目录 try: os.rmdir(update_path) except: pass # 删除空的更新主目录 try: os.rmdir(update_folder) except: pass # 如果直接运行此脚本 if __name__ == '__main__': sg_update_plugin()