zoukankan      html  css  js  c++  java
  • 学习用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:atch_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] "	"
                    newName = trimLeft iniLine[2] "	"
                    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 ("	["+oldName+"]		RenameTo:		["+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 + "		"+localtime)
            func_rename = fn_RenameAllMax()
            savemaxfile maxpathline clearNeedSaveFlag:true quiet:true
        )
    )
    
    close inifile
    close batchfile
    
    ---------------------- output logs --------------------------------------------
    append outputLogs ("
    -------------------------------------------------------")
    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();
        }
    }
  • 相关阅读:
    ASP.NET MVC3 系列教程 部署你的WEB应用到IIS 6.0
    ASP.NET MVC3 系列教程 控制器 & 视图
    Windows 8 如何安装到Virtual Box虚拟机上(x86)
    工具脚本(网络编码)
    c库的rand/random随机数产生函数性能差?
    shell脚本模版
    linux的IO调度算法和回写机制
    thrift安装脚本
    通用高效的c++内存池(特定类型)
    [转] NoSQL生态系统
  • 原文地址:https://www.cnblogs.com/CloudLiu/p/10746060.html
Copyright © 2011-2022 走看看