日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

Python腳本修改Maya?ASCII文件路徑方法實現_python

作者:沐風老師 ? 更新時間: 2023-04-29 編程語言

以下腳本修改當前項目路徑和子文件夾中擴展名為“.ma”的所有文件,這樣您就可以輕松地一次編輯所有文件。此腳本搜索特定字符串replace_This變量并將其替換為with_This,您可以使用它更改引用路徑、紋理路徑等…

話不多說直接上腳本:

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 命令方法

有幾種方法可以在 Maya 中輸入 Python。

1.腳本編輯器(Script Editor)

為了便于在 Maya 中同時使用 MEL 和 Python 腳本,“腳本編輯器”(Script editor)已修改為每種語言具有單獨的選項卡。輸入到 MEL 選項卡窗口中的語句將發送到 MEL 進行處理;同樣,輸入到 Python 選項卡窗口中的語句將由 Python 處理。

從 Python 返回的結果會帶有 Python 注釋字符 (#) 前綴。

您可以直接在選項卡中輸入命令,也可以將加載現有 .py 文件到選項卡中。

注:
在腳本編輯器中,可借助自動完成來更快地查找命令名。

2.命令行和“工具架”(Shelf)

也可在命令行輸入簡短的 Python 命令。通過切換可選擇輸入 MEL 命令或 Python 命令。

與 MEL 腳本類似,也可使用鼠標中鍵 () 將 Python 腳本拖動到“工具架”(Shelf)。此時將出現一個對話框,詢問腳本是 Python 腳本還是 MEL 腳本。

原文鏈接:https://blog.csdn.net/mufenglaoshi/article/details/128950350

欄目分類
最近更新