This commit is contained in:
Jeffreytsai1004 2025-01-14 02:11:34 +08:00
parent 024937e627
commit ce678534b2
3 changed files with 327 additions and 0 deletions

126
Scripts/Dev/mayaiconview.py Normal file
View File

@ -0,0 +1,126 @@
import os
import maya.cmds as cmds
# 全局变量
favorites = [] # 存储收藏的图标
MAX_FAVORITES = 15 # 收藏夹最大容量
ICON_SIZE = 50 # 图标大小(像素)
COLUMNS = 15 # 图标网格的列数
ROWS = 10 # 图标网格的可见行数
WINDOW_NAME = "mayaIconViewer" # 窗口名称
def create_icon_viewer():
"""创建并显示图标查看器窗口"""
window_width = COLUMNS * ICON_SIZE
# 如果窗口已存在,则删除
if cmds.window(WINDOW_NAME, exists=True):
cmds.deleteUI(WINDOW_NAME)
# 创建主窗口
cmds.window(WINDOW_NAME, title="Maya 图标查看器", width=window_width)
main_layout = cmds.columnLayout(adjustableColumn=True)
# 添加UI元素
create_ui_elements(window_width)
update_icons()
cmds.showWindow(WINDOW_NAME)
def create_ui_elements(width):
"""创建说明文字"""
cmds.text(label="单击图标复制名称并添加到收藏夹 - 注意:搜索过程可能较慢,请耐心等待",
align="center", font="boldLabelFont", width=width)
cmds.textFieldGrp("searchField", label="搜索:",
columnWidth=[(1, 50), (2, width-70)],
changeCommand=update_icons)
create_favorites_area()
create_icon_grid()
def create_favorites_area():
"""创建收藏夹区域"""
cmds.separator(height=10, style='none') # 添加一些间距
cmds.text(label="收藏夹", align='left', font="boldLabelFont")
cmds.separator(height=5, style='none') # 再添加一些间距
global favorites_layout
favorites_layout = cmds.rowLayout(numberOfColumns=MAX_FAVORITES+1,
columnWidth1=45,
adjustableColumn=2,
columnAttach=[(1, 'left', 0), (2, 'left', 0)],
height=50,
backgroundColor=[0.2, 0.2, 0.2])
# 添加星形图标(不可点击)
cmds.symbolButton(image="SE_FavoriteStar.png", width=45, height=45,
enable=False, annotation="收藏夹:单击图标可以快速复制名称")
# 创建收藏夹图标位置
for _ in range(MAX_FAVORITES):
cmds.symbolButton(parent=favorites_layout, width=45, height=45, visible=False)
cmds.setParent('..')
cmds.separator(height=10, style='none') # 添加底部间距
def create_icon_grid():
"""创建图标网格"""
global scroll_layout, grid_layout
scroll_layout = cmds.scrollLayout(horizontalScrollBarThickness=16,
verticalScrollBarThickness=16)
grid_layout = cmds.gridLayout(numberOfColumns=COLUMNS,
cellWidthHeight=(ICON_SIZE, ICON_SIZE))
def update_icons(*args):
"""更新图标显示"""
search_term = cmds.textFieldGrp("searchField", query=True, text=True).lower()
# 清除现有的图标
for child in cmds.gridLayout(grid_layout, query=True, childArray=True) or []:
cmds.deleteUI(child)
# 添加匹配的图标
for icon in cmds.resourceManager(nameFilter="*.png"):
if search_term in icon.lower():
cmds.symbolButton(parent=grid_layout, image=icon, width=45, height=45,
command=lambda x, i=icon: handle_click(i), annotation=icon)
adjust_layout()
def adjust_layout():
"""调整布局大小"""
visible_icons = len(cmds.gridLayout(grid_layout, query=True, childArray=True) or [])
total_rows = -(-visible_icons // COLUMNS) # 向上取整
scroll_height = min(total_rows, ROWS) * ICON_SIZE
cmds.scrollLayout(scroll_layout, edit=True, height=scroll_height)
cmds.window(WINDOW_NAME, edit=True, height=scroll_height + 180)
def handle_click(icon):
"""处理图标点击事件"""
copy_to_clipboard(icon)
add_to_favorites(icon)
def copy_to_clipboard(icon):
"""复制图标名称到剪贴板"""
os.popen(f'cmd /c echo {icon} | clip')
def add_to_favorites(icon):
"""添加图标到收藏夹"""
global favorites
if icon not in favorites:
if len(favorites) >= MAX_FAVORITES:
favorites.pop(0) # 如果收藏夹已满移除最<E999A4><E69C80><EFBFBD>的图标
favorites.append(icon)
update_favorites()
def update_favorites():
"""更新收藏夹显示"""
children = cmds.layout(favorites_layout, query=True, childArray=True)
for i, child in enumerate(children[1:], 1): # 跳过第一个子元素(星形图标)
if i <= len(favorites):
cmds.symbolButton(child, edit=True, image=favorites[i-1], visible=True,
command=lambda x, icon=favorites[i-1]: copy_to_clipboard(icon))
else:
cmds.symbolButton(child, edit=True, visible=False)
if __name__ == "__main__":
create_icon_viewer()

View File

@ -0,0 +1,174 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import maya.cmds as cmds
import sys
def onMayaDroppedPythonFile(*args):
run()
#Let's you batch import:
def run(*args):
if CheckForBonusTools:
multipleFilters = 'All native importable files (*.3ds *.abc *.ass *.at *.catpart *.dae *.fbx *.igs *.iges *.jt *.ma *.mb *.obj *.prt *.sat *.step *.stp *.wire);; Maya binary (*.mb);; Maya Ascii (*.ma);; WIRE_ATF (*.wire);; Obj (*.obj);; FBX (*.fbx);; DAE_FBX (*.dae);; Alembic Cache (*.abc);; Atom (*.atom);; Step (*.stp *.step);; IGES_ATF (*.igs *.iges);; ASS (*.ass);; 3DS Max (*.3ds);; CATIAV5_ATF (*.catpart);; JT_ATF (*.jt);; SAT_ATF (*.sat);; NX_ATF (*.prt)'
else:
multipleFilters = 'All native importable files (*.abc *.ass *.at *.catpart *.dae *.fbx *.igs *.iges *.jt *.ma *.mb *.obj *.prt *.sat *.step *.stp *.wire);; Maya binary (*.mb);; Maya Ascii (*.ma);; WIRE_ATF (*.wire);; Obj (*.obj);; FBX (*.fbx);; DAE_FBX (*.dae);; Alembic Cache (*.abc);; Atom (*.atom);; Step (*.stp *.step);; IGES_ATF (*.igs *.iges);; ASS (*.ass);; 3DS Max (*.3ds);; CATIAV5_ATF (*.catpart);; JT_ATF (*.jt);; SAT_ATF (*.sat);; NX_ATF (*.prt)'
files = cmds.fileDialog2(caption = 'Choose files to import', ds = 2, fileMode = 4, okCaption = 'Import', fileFilter = multipleFilters, hideNameEdit = False)
# 添加检查以确保 files 有效
if not files or not isinstance(files, list) or len(files) == 0:
cmds.warning('未选择任何文件,导入操作已取消。')
return # 直接返回,避免后续代码执行
for x in files:
if any(y in x for y in ['.ma', '.MA']):
fileType = 'mayaAscii'
options = ''
ImportFiles(fileType, x, options)
if any(y in x for y in ['.mb', '.MB']):
fileType = 'mayaBinary'
options = ''
ImportFiles(fileType, x, options)
if any(y in x for y in ['.wire', '.WIRE']):
fileType = 'WIRE_ATF'
options = ''
LoadPlugin('ATFPlugin')
ImportFiles(fileType, x, options)
if any(y in x for y in ['.obj', '.OBJ']):
fileType = 'OBJ'
options = 'mo=0'
ImportFiles(fileType, x, options)
if any(y in x for y in ['.fbx', '.FBX']):
fileType = 'FBX'
options = ''
LoadPlugin('fbxmaya')
ImportFiles(fileType, x, options)
if any(y in x for y in ['.dae', '.DAE']):
fileType = 'DAE_FBX'
options = ''
ImportFiles(fileType, x, options)
if any(y in x for y in ['.abc', '.ABC']):
fileType = 'Alembic'
options = ''
LoadPlugin('AbcImport')
ImportFiles(fileType, x, options)
if any(y in x for y in ['.atom', '.ATOM', '.at', '.AT']):
fileType = 'atomImport'
options = ''
LoadPlugin('atomImportExport')
ImportFiles(fileType, x, options)
if any(y in x for y in ['.step', '.STEP', '.stp', '.STP']):
fileType = 'STEP_ATF'
options = ''
LoadPlugin('ATFPlugin')
ImportFiles(fileType, x, options)
if any(y in x for y in['igs.', '.IGS', '.iges', '.IGES']):
fileType = 'IGES_ATF'
options = ''
LoadPlugin('ATFPlugin')
ImportFiles(fileType, x, options)
if any(y in x for y in['.ass', '.ASS']):
fileType = 'ASS'
options = ''
LoadPlugin('mtoa')
ImportFiles(fileType, x, options)
if any(y in x for y in['.3ds', '.3DS']):
fileType = '3ds'
options = ''
if CheckForBonusTools:
LoadPlugin('3ds')
ImportFiles(fileType, x, options)
if any(y in x for y in['.catpart', '.CATPART']):
fileType = 'CATIAV5_ATF'
options = ''
LoadPlugin('ATFPlugin')
ImportFiles(fileType, x, options)
if any(y in x for y in['.jt', '.JT']):
fileType = 'JT_ATF'
options = ''
LoadPlugin('ATFPlugin')
ImportFiles(fileType, x, options)
if any(y in x for y in['.sat', '.SAT']):
fileType = 'SAT_ATF'
options = ''
LoadPlugin('ATFPlugin')
ImportFiles(fileType, x, options)
if any(y in x for y in['.prt', '.PRT']):
fileType = 'NX_ATF'
options = ''
LoadPlugin('ATFPlugin')
ImportFiles(fileType, x, options)
def CheckForBonusTools(*args):
for x in sys.path:
if 'MayaBonusTools' in x:
return True
return False
def LoadPlugin(plugin, *args):
if not cmds.pluginInfo(plugin, query = True, loaded = True):
try:
cmds.loadPlugin(plugin)
sys.stdout.write('Plugin "' + plugin + '" loaded.\n')
except(RuntimeError):
cmds.warning('Could not find "' + plugin + '" plugin or could not load it. Open the Plugin Manager and make sure Maya recognized the plugin and try again.\n')
def ImportFiles(fileType, file, options, *args):
namespace = file.split('/')
namespace = namespace[-1].split('.')
namespace = namespace[0]
try:
cmds.file(str(file), i = True, type = fileType, ignoreVersion = True, mergeNamespacesOnClash = False, namespace = namespace, options = options)
sys.stdout.write('Imported "' + str(file) + '".\n')
except(UnicodeEncodeError):
sys.stdout.write('Either the directory path or the file name have some special characters.\n')
sys.stdout.write('The names will be changed.\n')
cmds.file(file, i = True, type = fileType, ignoreVersion = True, mergeNamespacesOnClash = False, namespace = namespace, options = options)
sys.stdout.write('Imported "' + file + '".\n')
except(ImportError):
cmds.warning('Could not import ' + file + '. Maybe you dont have the requiered permissions to the folder.\n')
if __name__ == '__main__':
if not cmds.about(batch = True):
run()

View File

@ -0,0 +1,27 @@
import maya.cmds as cmds
def run():
cmds.upAxis(axis='y')
cmds.delete("DHIhead:spine_04", "Lights", "export_geo_GRP", "head_grp")
cmds.rename("rig", "body_rig")
cmds.rename("geometry_grp", "body_geometry_grp")
body_grp_lock = cmds.listRelatives('body_grp', allDescendents=True, type='transform')
for obj in body_grp_lock:
cmds.setAttr(obj + '.translateX', lock=False)
cmds.setAttr(obj + '.translateY', lock=False)
cmds.setAttr(obj + '.translateZ', lock=False)
cmds.setAttr(obj + '.rotateX', lock=False)
cmds.setAttr(obj + '.rotateY', lock=False)
cmds.setAttr(obj + '.rotateZ', lock=False)
cmds.setAttr(obj + '.scaleX', lock=False)
cmds.setAttr(obj + '.scaleY', lock=False)
cmds.setAttr(obj + '.scaleZ', lock=False)
correctiveCube = cmds.polyCube()[0]
cmds.parent('root_drv', correctiveCube)
cmds.rotate(-90,0,0,correctiveCube,relative=True)
cmds.parent('root_drv',world=True)
cmds.delete(correctiveCube)
save_path = cmds.fileDialog2(fileMode=0, caption="Save Maya Scene", fileFilter="Maya Binary (*.mb)")[0]
cmds.file(rename=save_path)
cmds.file(save=True, type='mayaBinary')