This commit is contained in:
2025-11-25 00:43:56 +08:00
parent 61112bde7f
commit 3bbaa70350
4 changed files with 57 additions and 355 deletions

View File

@@ -14,7 +14,7 @@ import maya.cmds as cmds
import maya.mel as mel
import maya.OpenMaya as om
#from math import isclose
# from sys import exit # 已移除,避免 SystemExit 错误
# from sys import exit # Removed to avoid SystemExit error
##################################################################################################################################################################################################################
@@ -71,8 +71,10 @@ def documentation():
def assist_message(message, time, to_exit=True): # ---------- DONE
#POPS UP A MESSAGE ON THE USER'S SCREEN TO INFORM THEM OF SOMETHING
cmds.inViewMessage(amg="<hl>" + message + "<hl>", pos='midCenter', fade=True, fst=time, ck=True)
# Also display warning in Script Editor
cmds.warning(message)
if to_exit:
return # 不使用 exit(),避免 SystemExit 错误
return # Do not use exit() to avoid SystemExit error
def get_constraint_attribute(constraint_type):
#SETS A KEY ON THE START AND END OF THE TIMELINE, SO THAT WE ENSURE THERE'S A BLEND NODE ALL THE TIME. IF THERE'S NO KEY BEFORE ADDING THE SETUP, THE SCRIPT WON'T APPLY A SWITCH ON THE BLEND NODE
@@ -736,9 +738,9 @@ def delete_setup():
try:
_delete_setup_impl()
except Exception as e:
# 捕获所有错误,避免 SystemExit
# Catch all errors to avoid SystemExit
if "SystemExit" not in str(type(e)):
cmds.warning("Delete setup failed: " + str(e)) # ✓ 使用字符串拼接
cmds.warning("Delete setup failed: " + str(e)) # Using string concatenation for Python 2.7 compatibility
def _delete_setup_impl():
clear_keys = cmds.checkBoxGrp("remove_unnecessary_keys", q=True, v1=True)
@@ -851,7 +853,7 @@ import maya.cmds as cmds
import maya.mel as mel
import maya.OpenMaya as om
# from sys import exit # 已移除,避免 SystemExit 错误
# from sys import exit # Removed to avoid SystemExit error
bake_interval = """ + str(cmds.intFieldGrp("BakeInterval_IntField", q=True, v1=True)) + """
apply_key_reducer = """ + str(cmds.checkBoxGrp("ApplyKeyReducer_CheckBox", q=True, v1=True)) + """
@@ -912,9 +914,10 @@ def set_form_layout_coordinates(form_layout, name, top_coordinates, left_coordin
def assist_message(message, time, to_exit=True): # ---------- DONE
#POPS UP A MESSAGE ON THE USER'S SCREEN TO INFORM THEM OF SOMETHING
cmds.inViewMessage(amg="<hl>" + message + "<hl>", pos='midCenter', fade=True, fst=time, ck=True)
# 不再使用 exit(),因为它会在 Maya 中产生 SystemExit 错误
# 调用者应该检查返回值并决定是否继续执行
return not to_exit # 返回 False 表示应该停止True 表示可以继续
# Also display warning in Script Editor
cmds.warning(message)
if to_exit:
return # Do not use exit() to avoid SystemExit error
def get_constraint_attribute(constraint_type):
#SETS A KEY ON THE START AND END OF THE TIMELINE, SO THAT WE ENSURE THERE'S A BLEND NODE ALL THE TIME. IF THERE'S NO KEY BEFORE ADDING THE SETUP, THE SCRIPT WON'T APPLY A SWITCH ON THE BLEND NODE
@@ -1127,6 +1130,7 @@ def get_original_fk_controls(): # ---------- DONE
fk_ctrls = cmds.ls(sl=True)
if len(fk_ctrls) != 3:
assist_message("Incorrect number of controls selected. To apply an IK setup, you need to select 3 FK controls, in order of parent to child.", 4000)
return None
cmds.select(cl=True)
return fk_ctrls
@@ -1338,6 +1342,7 @@ def get_original_ik_controls():
ik_ctrls = cmds.ls(sl=True)
if len(ik_ctrls) != 2:
assist_message("Incorrect number of controls selected. To apply an FK setup, you need to select the Pole Vector first and then the IK Control, in order.", 4000)
return None
cmds.select(cl=True)
return ik_ctrls
@@ -1668,7 +1673,7 @@ def extraOptions():
cmds.showWindow("Extra_Options")
# 导出主要函数,使其可以从外部调用
# Export main functions for external use
__all__ = [
'fk_to_ik',
'ik_to_fk',
@@ -1676,14 +1681,15 @@ __all__ = [
'documentation',
'extraOptions',
'user_interface',
'show',
]
def show():
"""
便捷函数:启动 IK/FK Switcher UI
Convenience function: Launch IK/FK Switcher UI
使用方法:
Usage:
import animation_tools.ik_fk_switcher as ikfk
ikfk.show()
"""