?=以下脚本修改当前项目路径和子文件夹中扩展名为“.ma”的所有文件,这样您就可以轻松地一次编辑所有文件。此脚本搜索特定字符串rePlace_this变量并将其替换为with_This,您可以使用它更改引用路径、纹理路径等&hellIP;
话不多说直接上脚本:
import Maya.cmds as cmds import re import glob, os # – Define our search and replace replace_this ='string you want to replace' with_this = "" # - Get your Project path projectPath=cmds.workspace(q=True, rd=True) scenesPath= projectPath+"scenes/" # – use a regex to do the substitutiON as that is very qUIck regex = re.compile(replace_this) os.chDIr(scenesPath) for root, dirs, Files in os.walk(scenesPath): for file in files: if file.endswith(".ma"): print(root+'/'+file) filepath = root+'/'+file with open(filepath, "r") as read_stream: lines=read_stream.read() with open(filepath, "w") as write_stream: write_stream.write(regex.sub(with_this, lines)) print "工作完成..."
有几种方法可以在 Maya 中输入 python。
1.脚本编辑器(Script Editor)
为了便于在 Maya 中同时使用 MEL 和 Python 脚本,“脚本编辑器”(Script editor)已修改为每种语言具有单独的选项卡。输入到 MEL 选项卡窗口中的语句将发送到 MEL 进行处理;同样,输入到 Python 选项卡窗口中的语句将由 Python 处理。
从 Python 返回的结果会带有 Python 注释字符 (#) 前缀。
您可以直接在选项卡中输入命令,也可以将加载现有 .py 文件到选项卡中。
也可在命令行输入简短的 Python 命令。通过切换可选择输入 MEL 命令或 Python 命令。
与 MEL 脚本类似,也可使用鼠标中键 () 将 Python 脚本拖动到“工具架”(Shelf)。此时将出现一个对话框,询问脚本是 Python 脚本还是 MEL 脚本。
到此这篇关于Python脚本修改Maya ASCII文件路径方法实现的文章就介绍到这了,更多相关Python修改Maya ASCII文件路径内容请搜索云初冀北以前的文章或继续浏览下面的相关文章希望大家以后多多支持云初冀北!
$
还没有评论,来说两句吧...