学习用MaxScipt批处理Max文件

 

学习用MaxScipt批处理Max文件

需求

对几百个.max文件中的指定指定名称的骨骼进行重命名。

解决

考虑到是一次性需求,花了两个钟用maxscript实现了功能,基本逻辑把改名规则做成配置文本,然后一个个加载文件夹中的max档更加配置给节点改名。

为了方便以后使用,又用winform写了个带详细使用说明的界面,这个界面可以编辑配置文件,指定批处理文件夹,最后通过cmd来启动3dsmax执行这个脚本:

MaxScript:

-- by Tongyun Liu
-- 2017-4-27
----------------- define variables -------------------------------
logpath = @"D:\BoneRename.txt"
inipath = @"D:\RenameLog.ini"
batchpath = @"D:\batch_Directories.ini"

outputLogs = #()
inifile = openfile inipath

----------------- define functions -------------------------------
fn fn_RenameAllMax =
(
    batchfile = openfile batchpath
    while not eof inifile do
    (
        iniLine = #()
        iniLine = filterString (readline inifile) "="

        if(iniLine!= undefined) then
        (
            len = iniLine.count
            if(len == 2) then
            (
                oldName = trimRight iniLine[1] "\t"
                newName = trimLeft iniLine[2] "\t"
                if(oldName !=undefined) and (oldName !=undefined)and(oldName !=undefined) then
                (
                    bobj = execute("$'"+oldName+"'")
                    for o in objects
                        where (classof(o) == biped_object) or (classof(0) == BoneGeometry) do
                    (
                        if((bobj != undefined) and (o.name == bobj.name)) then
                        (
                            append outputLogs ("\t["+oldName+"]\t\tRenameTo:\t\t["+newName+"]")
                            bobj.name = newName
                        )
                    )
                )
            )
        )
    )
    return 1
)

--------------------------------- batch rename -------------------------------------
while not eof batchfile do
(
    maxpathline = readline batchfile
    if(maxpathline != "")and((findstring maxpathline ".max") != undefined) then
    (
        loadmaxfile maxpathline
        append outputLogs ("MaxFileName: "+maxpathline + "\t\t"+localtime)
        func_rename = fn_RenameAllMax()
        savemaxfile maxpathline clearNeedSaveFlag:true quiet:true
    )
)

close inifile
close batchfile

---------------------- output logs --------------------------------------------
append outputLogs ("\n-------------------------------------------------------")
logfile = openfile logpath mode:"a+"
print outputLogs to: logfile
close logfile
shelllaunch "notepad.exe" logpath

quitmax #noPrompt

命令行启动和操作3dsmax

在winform中启动max并执行maxScript的方法:

private void RunCmd()
{
    Process process =  new Process();
    string maxExePath = "3dsmax.exe所在的文件夹路径";
    string maxScriptPath = "需要执行maxscript脚本的路径";
    process.StartInfo.WorkingDirectory = maxExePath;
    process.StartInfo.FileName = "3dsmax.exe"
    process.StartInfo.Arguments = " -silent -mip -u MAXScript " + maxScriptPath;

    process.Start();
    process.WaitForExit();

    if(process.HasExited)
    {
        process.Close();
    }
}

转载于:https://www.cnblogs.com/CloudLiu/p/10746060.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值