自定义属性中的Maxscript FileIn

时间:2016-03-21 17:17:51

标签: custom-attributes maxscript

我在自定义属性中遇到FileIn()问题。每次我第一次执行我的脚本时,我都会得到一个未定义的类或函数。另外,当我关闭3ds max并使用我的自定义属性重新打开场景时,我总是会收到错误。

我希望有人可以帮助我理解我在代码中做错了什么。我真的希望有一个解决方案,因为FileIn()对我来说非常有用,可以重用和组织我的代码。在此先感谢您的帮助:)

这是我的代码:

Global newAttrib = attributes posAttribs
(
fn addFunction FolderName vArray=
(
/*
1)  Get the root position of the installed position of 3ds max
2)  Get in the script file and then in the FolderName of the function
3)  Add all the function inside the vArray in a FileIn Loop
*/
for i = 1 to vArray.count do
(
FolderPosition =  ((GetDir #maxroot)+"\scripts\\" +FolderName + "\\")
FileIn(FolderPosition + vArray[i])
)
)
parameters Param0 rollout:General
(
pPreset0 type:#String ui:ddl_Preset0 default:"..."
pTableHeight type:#Float ui:spn_Height default:100
)--end Param1
parameters Param1 rollout:TopPart
(
pPreset1 type:#String ui:ddl_Preset1 default:"..."
defaultArray1 type:#stringTab tabSize:1 tabSizeVariable:true
defaultExist1 type:#boolean default:False
)--end Param1
parameters Param2 rollout:BottomPart
(
pPreset2 type:#String ui:ddl_Preset2 default:"..."
pLegEndShape type:#String ui:ddl_LegEnd default:"..."
defaultArray2 type:#stringTab tabSize:1 tabSizeVariable:true
defaultExist2 type:#boolean default:False
)--end Param2
parameters Param3 rollout:Supports
(
pPreset3 type:#String ui:ddl_Preset3 default:"..."
defaultArray3 type:#stringTab tabSize:1 tabSizeVariable:true
defaultExist3 type:#boolean default:False
)--end Param3

Local externalFn = #("UI_CaptionChange.ms", "UI_ControlVisible.ms", "UI_MoveVisible.ms")
Local externalMod = #("MOD_Extrude.ms", "MOD_Taper.ms", "MOD_QuadChamfer.ms", "MOD_SweepModifier.ms")
Local TableTypes = sort(#("...", "Dining", "Workbench", "Coffee", "Round"))
Local TopTypes = sort(#("...", "Square", "Rectangle", "Round","Oval","Triangle", "NGon", "Semi Circle", "Quarter Circle"))
Local LegTypes = sort(#("...", "Straight", "Taper", "Cross","U","MultiEnd", "X", "Curve", "T"))
Local LegEndTypes = sort(#("...", "Square", "Rectangular", "Circle","NGon"))
Local SupportTypes = sort(#("...", "CopyTop", "PTP"))
Rollout General "General"
(
dropdownlist ddl_Preset0 "Presets:" items:TableTypes
spinner spn_Height "Height" range:[0,1000,100] type:#float
button btn_Random "Random All" border:True
on General open do
(
addFunction "Mal_Functions" externalFn --Adding all the external function
addFunction "Mal_Modifiers" externalMod --Adding all the external modifiers
ddl_Preset0.selection = findItem ddl_Preset0.items pPreset0
UICaptionChange General 2 "Test"
)
on ddl_Preset0 selected val do
(
pPreset0 = ddl_Preset0.selected
)
)--end TopPart Rollout

Rollout TopPart "Top Part"
(
dropdownlist ddl_Preset1 "Presets:" items:TopTypes
spinner spn_Thickness "Height" range:[0,1000,2] type:#float
spinner spn_Length "Length" range:[0,1000,2] type:#float
spinner spn_Width "Width" range:[0,1000,2] type:#float
on TopPart open do
(
ddl_Preset1.selection = findItem ddl_Preset1.items pPreset1
if defaultExist == False then
(
--defaultArray = UIDefault Testing
--defaultExist = True
)
)
on ddl_Preset1 selected val do
(
pPreset1 = ddl_Preset1.selected
)
)--end TopPart Rollout
Rollout BottomPart "Bottom Part"
(
dropdownlist ddl_Preset2 "Presets:" items:LegTypes
dropdownlist ddl_LegEnd "Leg End Shape:" items:LegEndTypes
on BottomPart open do
(
ddl_Preset2.selection = findItem ddl_Preset2.items pPreset2
ddl_LegEnd.selection = findItem ddl_LegEnd.items pLegEndShape
)
on ddl_Preset2 selected val do
(
pPreset2 = ddl_Preset2.selected
)

on ddl_LegEnd selected val do
(
pLegEndShape = ddl_LegEnd.selected
)
)--end BottomPart Rollout
Rollout Supports "Supports"
(
dropdownlist ddl_Preset3 "Presets:" items:SupportTypes
on Supports open do
(
ddl_Preset3.selection = findItem ddl_Preset3.items pPreset3
)
on ddl_Preset3 selected val do
(
pPreset3 = ddl_Preset3.selected
)
)--end Supports Rollout
)--end posAttribs
modPanel.addModToSelection (EmptyModifier ()) ui:on
custAttributes.add $.modifiers[1] newAttrib --add the attribute in the first modifier

2 个答案:

答案 0 :(得分:0)

函数UICaptionChange未在您的MaxScript文件中定义,所以我会在您引用的文件中猜测它?

我不是百分之百确定这一点,但我的猜测是因为maxscript在执行之前已经解析了“open”函数,它将在运行定义新函数的FileIn命令之前解析functino。换句话说,你找到的功能太晚了,无法找到它们。

我建议将addFunction调用仅移动到一般主体上的全局范围。找到在执行过程中自行编写的代码非常令人困惑。此外,每次创建/打开属性时,您将重新解析这些包含的文件,因此您每次都需要支付重新编译的费用。

只需移动代码以将文件包含到文件头部(在全局范围内),它将仅在评估脚本时执行,并且您应该没问题

答案 1 :(得分:0)

对不起我迟到的回复我几天没回家。 我想我做了你说的话。

我创建了一个startup.ms文件,它位于3ds max脚本文件夹中。 在该文件中,我添加了我的addFunction,然后通过添加ally我的其他函数(分离的maxscript文件)来调用它。这就像添加一个功能库。现在从我所看到的,它似乎是诀窍。再次感谢你的帮助。我真的很认可它:)