#这个工具目前import是识别不到文件夹中的ass文件的 请修改整合代码
import maya.cmds as cmds
import maya.mel as mel
import os
# ===== 导出功能 =====
def export_selected_objects_to_ass(output_dir, prefix="geo_", suffix=""):
"""
批量导出选中的 transform 对象为单独的 .ass 文件
"""
output_dir = os.path.normpath(output_dir.strip())
print(f"📁 Final output path: {output_dir}")
print(f"📁 Path exists: {os.path.exists(output_dir)}")
try:
os.makedirs(output_dir)
print(f"🆕 Directory created: {output_dir}")
except FileExistsError:
print(f"📂 Directory already exists: {output_dir}")
except Exception as e:
cmds.warning(f"❌ Failed to create directory: {output_dir}, Error: {str(e)}")
return
selected = cmds.ls(selection=True, dag=True, type='transform')
if not selected:
cmds.warning("Please select one or more transform objects.")
return
print(f"Exporting {len(selected)} selected objects...")
for obj in selected:
file_name = f"{prefix}{obj}{suffix}.ass"
full_path = os.path.join(output_dir, file_name)
cmds.select(obj, replace=True)
try:
full_path = full_path.replace("\\", "/")
mel.eval(f'arnoldExportAss -f "{full_path}" -selected 1 -mask 1 -light 0 -camera 0;')
print(f"✅ Exported: {full_path}")
except Exception as e:
print(f"❌ Failed to export: {obj}, Error: {str(e)}")
cmds.select(clear=True)
print("✅ Export completed!")
# ===== 导入功能 =====
def import_ass_files_to_aiStandIn(import_dir):
"""
从指定路径加载所有 .ass 文件,并为每个文件创建一个 aiStandIn 节点
"""
import_dir = os.path.normpath(import_dir.strip())
if not os.path.exists(import_dir):
cmds.warning(f"❌ Import path does not exist: {import_dir}")
return
# 获取所有 .ass 文件
ass_files = [f for f in os.listdir(import_dir) if f.endswith(".ass")]
if not ass_files:
cmds.warning(f"❌ No .ass files found in directory: {import_dir}")
return
print(f"📁 Importing {len(ass_files)} .ass files from: {import_dir}")
spacing = 2.0 # 每个代理之间的偏移
count = 0
for i, ass_file in enumerate(ass_files):
file_name = os.path.splitext(ass_file)[0]
full_path = os.path.join(import_dir, ass_file).replace("\\", "/")
try:
# 创建 aiStandIn 节点
standin = cmds.createNode("aiStandIn", name=f"{file_name}_proxy")
cmds.setAttr(f"{standin}.dso", full_path, type="string")
# 设置位置偏移,防止重叠
x = (i % 5) * spacing
z = (i // 5) * spacing
cmds.move(x, 0, z, standin)
print(f"✅ Imported: {full_path} as {standin}")
except Exception as e:
print(f"❌ Failed to import: {ass_file}, Error: {str(e)}")
print("✅ Import completed!")
# ===== GUI 界面 =====
def create_ass_exporter_gui():
window_name = "ArnoldAssProxyExportTool"
if cmds.window(window_name, exists=True):
cmds.deleteUI(window_name)
window = cmds.window(window_name, title="Arnold Batch Export/Import .ass Proxy Tool", widthHeight=(400, 300))
main_layout = cmds.columnLayout(adjustableColumn=True, parent=window)
cmds.text(label="Export Settings", align="center", font="boldLabelFont")
cmds.separator(height=10, style="in")
# Export Path
export_path_layout = cmds.rowLayout(numberOfColumns=3, columnWidth3=[80, 250, 50], parent=main_layout)
cmds.text(label="Export Path")
export_path = cmds.textField(text="C:/temp/arnold_ass", width=250)
cmds.button(label="...", width=30, command=lambda x: select_output_dir(export_path))
cmds.setParent('..')
# Prefix
prefix_layout = cmds.rowLayout(numberOfColumns=2, columnWidth2=[80, 320], parent=main_layout)
cmds.text(label="Prefix")
prefix_field = cmds.textField(text="geo_", width=320)
cmds.setParent('..')
# Suffix
suffix_layout = cmds.rowLayout(numberOfColumns=2, columnWidth2=[80, 320], parent=main_layout)
cmds.text(label="Suffix")
suffix_field = cmds.textField(text="_high", width=320)
cmds.setParent('..')
# Export Button
cmds.button(label="Export",
command=lambda x: on_export(export_path, prefix_field, suffix_field),
height=30,
backgroundColor=[0.3, 0.6, 0.3],
width=400)
cmds.separator(height=15, style="none")
# Import Path
import_path_layout = cmds.rowLayout(numberOfColumns=3, columnWidth3=[80, 250, 50], parent=main_layout)
cmds.text(label="Import Path")
import_path = cmds.textField(text="C:/temp/arnold_ass", width=250)
cmds.button(label="...", width=30, command=lambda x: select_output_dir(import_path))
cmds.setParent('..')
# Import Button
cmds.button(label="Import",
command=lambda x: on_import(import_path),
height=30,
backgroundColor=[0.6, 0.3, 0.3],
width=400)
cmds.showWindow(window)
def select_output_dir(textfield):
selected_dir = cmds.fileDialog2(dialogStyle=2, fileMode=3)
if selected_dir:
selected_path = os.path.normpath(selected_dir[0])
print(f"📁 Selected path: {selected_path}")
cmds.textField(textfield, edit=True, text=selected_path)
def on_export(export_path, prefix_field, suffix_field):
output_dir = os.path.normpath(cmds.textField(export_path, query=True, text=True))
prefix = cmds.textField(prefix_field, query=True, text=True)
suffix = cmds.textField(suffix_field, query=True, text=True)
export_selected_objects_to_ass(output_dir, prefix, suffix)
def on_import(import_path):
import_dir = os.path.normpath(cmds.textField(import_path, query=True, text=True))
import_ass_files_to_aiStandIn(import_dir)
# 启动 GUI
create_ass_exporter_gui()
最新发布