February 19, 2023

MAXScript学习笔记

MAXScript学习笔记

环境配置

  • 设置后,可以返回操作的语�?/p>

  • VSCode环境配置

    • 将“initialize_COM_server.ms�?dsMax的开始目录下复制到startup
      • 通过 %localappdata%\autodesk\3dsmax ,在资料管理中找�?dsMAX的安装目�?/li>
      • 根据版本选择找到script\startup
      • 将“initialize_COM_server.ms”复制到此处
    • �?MXSPyCOM.exe 复制到任意位�?/li>
    • 建立工程�?ul>
    • 添加json文件
    • 将以下脚本粘�?
      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      {
      "version": "2.0.0",
      "tasks": [
      {
      "label": "Execute in Max",
      "type": "process",
      "command": "C:/MXSPyCOM.exe",
      "args": ["-f", "${file}"],
      "presentation": {
      "reveal": "always",
      "panel": "new"
      }
      }
      ]
      }

  • 调整vs的快捷键设置
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
        [

        {
            "key": "ctrl+e",

            "command": "workbench.action.tasks.runTask",

            "args": "Execute in Max"       

        },

        {

            "key": "shift+e",

            "command": "workbench.action.quickOpen"

        },

        {

            "key": "shift+e",

            "command": "workbench.action.quickOpenNavigateNextInFilePicker",

            "when": "inFilesPicker && inQuickOpen"

        }

    ]
  • 重启3dsMAX,在vscode编写脚本时,使用快捷键“Ctrl+E�?h2>实例
  • 1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    -- 导出资源的例�?/span>
    rollout AnimExporter "动画资产导出"
    (
    group "Export Setting" (

    edittext ExportPath "路径:"

    button GetCurrentPath "获取路径" width: 200 height:30


    )
    button Export "导出" width: 200 height:30
    button ShowIn "打开目录" width: 200 height:30
    -- Get Folder Path
    fn GetFolderPath =(
    folderPath = maxFilePath
    return folderPath
    )
    -- Fbx Export
    fn ExportFbx go assetPath =(
    path = assetPath+go.name
    exportFile path #noPrompt selectedOnly:true using:FBXEXP
    )

    -- Get Head Dummy
    fn GetHeadDummy gos =(
    result
    for i in gos do
    if Classof i == Dummy && i.children.count == 0 && i.parent==null do
    result =i
    return i
    )
    -- Get Polys
    fn GetPolys gos =(
    result = #()
    for i in gos do
    if Classof i == PolyMeshObject do
    append result i
    return result
    )

    fn GetHairPolys PolyMeshs =(
    result
    for i in PolyMeshs do (
    polyMeshName = i.name
    if matchpattern i.name pattern: "*Hair*" == true do (
    result = i
    )
    )
    return result
    )
    -- 获得所有子�?http://tk.v5cg.com/help/250.html
    fn RecurseChildren RecurseCollector currNode=
    (
    append RecurseCollector currNode
    local childNodes = currNode.children
    if(childNodes.count !=0)then for c in childNodes do
    (
    RecurseChildren RecurseCollector c
    )
    )

    fn GetChildrens currNode=
    (
    -- 清空集合
    RecurseCollector = #()
    -- 开始递归
    RecurseChildren RecurseCollector currNode
    -- 返回
    return RecurseCollector
    )
    -- 获得skin列表
    fn GetBipsOnSkin skin =(
    result = #()
    num = skinOps.GetNumberBones skin
    for i=1 to num do
    boneName = skinOps.GetBoneName skin i 0
    append result boneName
    return result
    )
    -- 按键
    on GetCurrentPath pressed do
    (
    path = GetFolderPath()
    if(path.count==0)
    then(
    messageBox "错误�?quot;
    )
    else(
    ExportPath.text = GetFolderPath()
    )

    )

    on Export pressed do
    (
    aa = $
    ExportFbx aa ExportPath.text
    )

    on ShowIn pressed do
    (

    a= $.modifiers[#Skin]
    cc = GetBipsOnSkin a
    for i in cc do
    print i

    )

    )

    -- 获取当前文件的地址
    -- 获取当前文件中的物体列表
    -- 列表
    -- Editable_Poly
    -- Dummy

    -- 获得层级的全部子�?/span>
    -- 创建组合好的选择列表
    -- 按mesh名创建FBX
    -- 分别导出到当前文件地址�?/span>



    createdialog AnimExporter 220 200

    霜狼_may-Maxscrip教程

  • 3ds MAXscript 脚本语言完全学习手册

  • 关于本文

    本文作�?Master Gong Sheng, 许可�?CC BY-NC 4.0.