往往我们拿到一些客户灯光整合文件中存在很多代理文件,比如Arnold的ass文件,Redshift的rs文件,正常来说这些代理文件不会二次赋予材质,材质都是写在代理文件里面的,材质的贴图路径你是看不到的,但是我们又必须check这些贴图是否存在,这里有两段代码,分别获取rs文件和ass文件的所使用到的贴图路径,运行代码很简单,打开Maya,随便导一些ass文件或者rs文件进来,然后在Script Editor中执行下面的Python代码即可获得所有贴图路径(这两段代码来自羊厂长打包王工具里的部分代码),代码到用时方恨少。
获取Redshift渲染器rs代理文件所有贴图路径代码:
import reimport codecsfrom pprint import pprintimport maya.cmds as cmdsdef readFileCode_bag2(path): con = "" if os.path.exists(path): Arg = codecs.open(path, "r") con = Arg.read() Arg.close() return congetAllRs = []getAllNodes = cmds.ls(type="RedshiftProxyMesh")tm = re.compile("(\\x00\\x00\\x00[A-Za-z]:/.*?\\x00)+")tm2 = re.compile("(\\x00\\x00\\x00//[0-9].*?\\x00)+")for node in getAllNodes: getPath = cmds.getAttr(node + ".fileName") if getPath and getPath not in getAllRs: getAllRs.append(getPath)for oneProxy in getAllRs: getAllPath = [] print(oneProxy) getCon = readFileCode_bag2(oneProxy) getResult = tm.findall(getCon) getResult2 = tm2.findall(getCon) for oneString in getResult: if oneString and "\\" not in oneString and "_map_auto" not in oneString and "/" in oneString: getPathMap = oneString.split("\x00\x00\x00")[1][:-1] if getPathMap and getPathMap not in getAllPath: getAllPath.append(getPathMap) for oneString in getResult2: if oneString and "\\" not in oneString and "_map_auto" not in oneString and "/" in oneString: getPathMap = oneString.split("\x00\x00\x00")[1][:-1] if getPathMap and getPathMap not in getAllPath: getAllPath.append(getPathMap) pprint(getAllPath)
获取Arnold渲染器ass代理文件所有贴图路径代码:
from pprint import pprintimport maya.cmds as cmdsimport arnold as ar# 分析ass代理文件贴图路径getAllAss = []getAllNodes = cmds.ls(type="aiStandIn")for node in getAllNodes: getPath = cmds.getAttr(node + ".dso") if getPath and getPath not in getAllAss: getAllAss.append(getPath)for ass in getAllAss: getAllPath = [] print(ass) ar.AiBegin() ar.AiMsgSetConsoleFlags(ar.AI_LOG_ALL) ar.AiASSLoad(ass, ar.AI_NODE_ALL) iterator = ar.AiUniverseGetNodeIterator(ar.AI_NODE_ALL) while not ar.AiNodeIteratorFinished(iterator): node = ar.AiNodeIteratorGetNext(iterator) if ar.AiNodeIs(node, "MayaFile") or ar.AiNodeIs(node, "image"): getPath = ar.AiNodeGetStr(node, "filename") if getPath and getPath not in getAllPath: getAllPath.append(getPath) ar.AiNodeIteratorDestroy(iterator) ar.AiEnd() pprint(getAllPath)
文字思路如果对你有用,就给作者赞赏加个鸡腿吧,蟹蟹~(3)~