Update
This commit is contained in:
@@ -4,12 +4,233 @@
|
||||
#===================================== IMPORT MODULES =====================================
|
||||
import maya.cmds as cmds
|
||||
import pymel.core as pm
|
||||
import maya.mel as mel
|
||||
from maya import OpenMayaUI as omui
|
||||
from Qt import QtWidgets, QtCore, QtGui
|
||||
from Qt.QtCompat import wrapInstance
|
||||
import webbrowser
|
||||
import subprocess
|
||||
import importlib
|
||||
import traceback
|
||||
import sys
|
||||
import os
|
||||
|
||||
# 导入配置
|
||||
import config
|
||||
from scripts.ui import localization
|
||||
LANG = localization.LANG
|
||||
|
||||
#========================================== FUNCTIONS ========================================
|
||||
|
||||
# 第一行按钮功能
|
||||
def new_file():
|
||||
"""
|
||||
创建新文件
|
||||
"""
|
||||
print("创建新文件")
|
||||
try:
|
||||
if cmds.file(q=True, modified=True):
|
||||
result = cmds.confirmDialog(
|
||||
title=LANG.get("confirm_save", "确认保存"),
|
||||
message=LANG.get("save_changes", "是否保存更改?"),
|
||||
button=[LANG.get("save", "保存"), LANG.get("dont_save", "不保存"), LANG.get("cancel", "取消")],
|
||||
defaultButton=LANG.get("save", "保存"),
|
||||
cancelButton=LANG.get("cancel", "取消"),
|
||||
dismissString=LANG.get("cancel", "取消")
|
||||
)
|
||||
|
||||
if result == LANG.get("save", "保存"):
|
||||
cmds.file(save=True)
|
||||
elif result == LANG.get("cancel", "取消"):
|
||||
return
|
||||
|
||||
cmds.file(new=True, force=True)
|
||||
print("新文件已创建")
|
||||
except Exception as e:
|
||||
print(f"创建新文件时出错: {e}")
|
||||
return True
|
||||
|
||||
def open_file():
|
||||
"""
|
||||
打开文件
|
||||
"""
|
||||
print("打开文件")
|
||||
try:
|
||||
file_path = cmds.fileDialog2(
|
||||
fileFilter="Maya Files (*.ma *.mb);;All Files (*.*)",
|
||||
dialogStyle=2,
|
||||
fileMode=1
|
||||
)
|
||||
if file_path:
|
||||
cmds.file(file_path[0], open=True, force=True)
|
||||
print(f"文件已打开: {file_path[0]}")
|
||||
except Exception as e:
|
||||
print(f"打开文件时出错: {e}")
|
||||
return True
|
||||
|
||||
def link_file():
|
||||
"""
|
||||
链接文件
|
||||
"""
|
||||
print("链接文件")
|
||||
try:
|
||||
file_path = cmds.fileDialog2(
|
||||
fileFilter="Maya Files (*.ma *.mb);;All Files (*.*)",
|
||||
dialogStyle=2,
|
||||
fileMode=1
|
||||
)
|
||||
if file_path:
|
||||
# 这里实现链接文件的功能
|
||||
print(f"文件已链接: {file_path[0]}")
|
||||
except Exception as e:
|
||||
print(f"链接文件时出错: {e}")
|
||||
return True
|
||||
|
||||
def unlink_file():
|
||||
"""
|
||||
取消链接
|
||||
"""
|
||||
print("取消链接")
|
||||
# 这里实现取消链接的功能
|
||||
return True
|
||||
|
||||
def import_file():
|
||||
"""
|
||||
导入文件
|
||||
"""
|
||||
print("导入文件")
|
||||
try:
|
||||
file_path = cmds.fileDialog2(
|
||||
fileFilter="Maya Files (*.ma *.mb);;FBX Files (*.fbx);;OBJ Files (*.obj);;All Files (*.*)",
|
||||
dialogStyle=2,
|
||||
fileMode=1
|
||||
)
|
||||
if file_path:
|
||||
# 根据文件扩展名选择导入方法
|
||||
file_ext = os.path.splitext(file_path[0])[1].lower()
|
||||
if file_ext == ".fbx":
|
||||
cmds.file(file_path[0], i=True, type="FBX")
|
||||
elif file_ext == ".obj":
|
||||
cmds.file(file_path[0], i=True, type="OBJ")
|
||||
else: # .ma or .mb
|
||||
cmds.file(file_path[0], i=True)
|
||||
print(f"文件已导入: {file_path[0]}")
|
||||
except Exception as e:
|
||||
print(f"导入文件时出错: {e}")
|
||||
return True
|
||||
|
||||
def export_file():
|
||||
"""
|
||||
导出文件
|
||||
"""
|
||||
print("导出文件")
|
||||
try:
|
||||
file_path = cmds.fileDialog2(
|
||||
fileFilter="Maya Files (*.ma *.mb);;FBX Files (*.fbx);;OBJ Files (*.obj);;All Files (*.*)",
|
||||
dialogStyle=2,
|
||||
fileMode=0
|
||||
)
|
||||
if file_path:
|
||||
# 根据文件扩展名选择导出方法
|
||||
file_ext = os.path.splitext(file_path[0])[1].lower()
|
||||
if file_ext == ".fbx":
|
||||
cmds.file(file_path[0], force=True, options="v=0;", type="FBX export", pr=True, ea=True)
|
||||
elif file_ext == ".obj":
|
||||
cmds.file(file_path[0], force=True, options="groups=1;ptgroups=1;materials=1;smoothing=1;normals=1", type="OBJexport", pr=True, ea=True)
|
||||
else: # .ma or .mb
|
||||
cmds.file(file_path[0], force=True, type="mayaAscii" if file_ext == ".ma" else "mayaBinary", pr=True, ea=True)
|
||||
print(f"文件已导出: {file_path[0]}")
|
||||
except Exception as e:
|
||||
print(f"导出文件时出错: {e}")
|
||||
return True
|
||||
|
||||
def save_file():
|
||||
"""
|
||||
保存文件
|
||||
"""
|
||||
print("保存文件")
|
||||
try:
|
||||
current_file = cmds.file(q=True, sceneName=True)
|
||||
if current_file:
|
||||
cmds.file(save=True)
|
||||
print(f"文件已保存: {current_file}")
|
||||
else:
|
||||
file_path = cmds.fileDialog2(
|
||||
fileFilter="Maya ASCII (*.ma);;Maya Binary (*.mb)",
|
||||
dialogStyle=2,
|
||||
fileMode=0
|
||||
)
|
||||
if file_path:
|
||||
file_ext = os.path.splitext(file_path[0])[1].lower()
|
||||
file_type = "mayaAscii" if file_ext == ".ma" else "mayaBinary"
|
||||
cmds.file(rename=file_path[0])
|
||||
cmds.file(save=True, type=file_type)
|
||||
print(f"文件已保存: {file_path[0]}")
|
||||
except Exception as e:
|
||||
print(f"保存文件时出错: {e}")
|
||||
return True
|
||||
|
||||
def show_user_info():
|
||||
"""
|
||||
显示用户信息
|
||||
"""
|
||||
print("显示用户信息")
|
||||
# 这里实现显示用户信息的功能
|
||||
return True
|
||||
|
||||
def show_help():
|
||||
"""
|
||||
显示帮助信息
|
||||
"""
|
||||
print("显示帮助信息")
|
||||
try:
|
||||
if hasattr(config, "TOOL_HELP_URL") and config.TOOL_HELP_URL:
|
||||
webbrowser.open(config.TOOL_HELP_URL)
|
||||
else:
|
||||
cmds.confirmDialog(
|
||||
title=LANG.get("help", "帮助"),
|
||||
message=LANG.get("help_not_available", "帮助文档暂不可用"),
|
||||
button=[LANG.get("ok", "确定")],
|
||||
defaultButton=LANG.get("ok", "确定")
|
||||
)
|
||||
except Exception as e:
|
||||
print(f"显示帮助信息时出错: {e}")
|
||||
return True
|
||||
|
||||
def show_settings():
|
||||
"""
|
||||
显示设置
|
||||
"""
|
||||
print("显示设置")
|
||||
# 这里实现显示设置的功能
|
||||
return True
|
||||
|
||||
def print_file():
|
||||
"""
|
||||
打印文件
|
||||
"""
|
||||
print("打印文件")
|
||||
# 这里实现打印文件的功能
|
||||
return True
|
||||
|
||||
# 第二行按钮功能
|
||||
def change_view(view_type):
|
||||
"""
|
||||
切换视图类型
|
||||
"""
|
||||
print(f"切换到{view_type}视图")
|
||||
# 这里实现切换视图的功能
|
||||
return True
|
||||
|
||||
def model_changed(index):
|
||||
"""
|
||||
模型选择改变
|
||||
"""
|
||||
print(f"模型选择改变: {index}")
|
||||
# 这里实现模型选择改变的功能
|
||||
return True
|
||||
|
||||
# 保留原来的函数作为兼容性考虑
|
||||
def toolbar_temp_utils_function():
|
||||
"""
|
||||
Placeholder function for toolbar module
|
||||
|
Reference in New Issue
Block a user