
La función getUserProp en MaxScript ha presentado errores desde versiones antiguas de 3ds Max,影响对象用户属性中存储的值的检索。为了解决这个问题,开发了一个改进版本,优化数据提取并确保更精确的处理。
长期错误的解决方案
原始MaxScript函数的问题在于,在处理布尔数据、数字或文本字符串时,并不总是返回正确的值。这个故障从3ds Max 9开始就存在,从未被官方修复。为了避免这些错误,设计了一个新实现,提高数据检索的稳定性。
改进版 getUserProp 的主要特性
- 数值内容验证,针对获取的值。
- 文本格式校正,避免转换错误。
- 兼容旧版本的3ds Max,包括版本 9。
- 优化的处理,针对布尔值、数字和文本字符串。
自动化脚本中的应用
此脚本特别适用于在3ds Max中使用自定义工具的开发者,因为它允许更精确地访问对象用户属性中存储的数据。其应用扩展到:
- 检索信息,从场景中的 3D 模型。
- 元数据自动化,改善项目组织。
- 高效导出,在自定义脚本中。
高级工作流程的优化
此新版本的实现便于在3ds Max环境中获取可靠数据。其目标是提高用户属性使用的 consistency 和稳定性,避免信息提取中的常见问题。
改进脚本代码
-- Verifica si una cadena contiene solo números
fn isNumeral txt = (
s= txt as string
for i = 1 to s.count do(
if(findString "0123456789" s[i]) == undefined then(
return false
)
)
return true
)
-- Función mejorada de getUserProp
fn getUserProp2 obj =(
local ss = (getUserPropBuffer obj) as stringStream
if ss != undefined then(
while (eof ss) != true do(
local txt = readline ss
local arr = filterstring txt " = "
if arr[2] != undefined then(
if (arr[2] == "true") or (arr[2] == "false") or ((isNumeral arr[2]) == true ) then(
txt = arr[1] + "=" + arr[2]
execute txt
readline ss
)else(
arr[2] = "@\"" + arr[2]
append arr[2] "\""
txt = arr[1] + "=" + arr[2]
execute txt
readline ss
)
)else(
txt = arr[1] + "=" + "\"\""
execute txt
readline ss
)
)
)else(
return();
)
代码解释
- isNumeral(txt): 检查字符串是否仅包含数字。
- getUserProp2(obj):
- 检索用户属性中存储的值。
- 验证它们是数字、布尔值还是文本字符串。
- 校正转换错误并正确结构化数据。
- 安全地执行值赋值。
此脚本是针对在3ds Max中处理存储数据的开发者的有效解决方案,消除错误并提高项目中信息检索的可靠性。