You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

3ds Max MaxScript遍历目录资产报错:No 'map' function for '*'

3ds Max脚本循环遍历子目录资产报错修复

问题概述

需求为遍历指定父目录下的所有子目录,列出每个子目录中的.max格式资产。无循环时可正常生成子目录列表,但添加循环后,Scripting Listener抛出错误:

Error occurred in anonymous codeblock; filename: E:\MUVA\MaxScript\teste.ms; position: 371; line: 9 -- No "map" function for "*"

必须重启3ds Max并移除循环才能恢复正常。原代码如下:

dirPath = getSavePath caption: "SELECT THE PARENT DIRECTORY"
dirList = getDirectories dirPath + "\*"
print ("Directories: " + dirList)

for dir in dirList do(
    assetsPath = dir + "\*.max"
    assetsList = getFiles assetsPath
    print ("List of assets: " + assetsList)
)

错误原因

  1. 路径拼接优先级错误:getDirectories dirPath + "\*"会先执行getDirectories dirPath(仅获取当前目录本身,而非子目录),再将返回的数组与字符串"\*"相加,导致dirList不是正确的子目录数组,而是错误的复合类型。
  2. 字符串转义问题:MaxScript中路径的反斜杠需要用双反斜杠\\转义,单反斜杠会被识别为转义符,导致路径格式错误。
  3. 字符串与数组直接拼接:print语句中直接用+连接字符串和数组,会触发类型不匹配的隐式转换错误。

修复后的代码

dirPath = getSavePath caption: "SELECT THE PARENT DIRECTORY"
-- 正确拼接子目录通配符路径,用双反斜杠转义,加括号确保参数完整传入
dirList = getDirectories (dirPath + "\\*")
-- 将数组转为字符串后再拼接输出
print ("Directories: " + (dirList as string))

for dir in dirList do(
    -- 正确拼接.max文件路径
    assetsPath = dir + "\\*.max"
    assetsList = getFiles assetsPath
    -- 转换数组为字符串后输出
    print ("List of assets: " + (assetsList as string))
)

关键修复点

  • 给getDirectories的路径参数添加括号,确保dirPath + "\\*"作为完整参数传入,正确获取所有子目录。
  • 所有路径中的反斜杠替换为双反斜杠\\,避免转义符解析错误。
  • 输出数组时先用as string将数组转换为字符串,再与文本拼接,避免类型不匹配问题。

内容的提问来源于stack exchange,提问作者Lucas Costanski

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.02 22:01:11