I've been pulling my hair out over trying to include in Maxscript from a variable.
I want my rollout to contain an arbitrary amount of subrollouts from external files, here's what I've got so far
try(destroyDialog testings)catch()
rootFolder = getFileNamePath (getThisScriptFilename())
sourceFolder = rootFolder + "source\\"
modulesFolder = "modules\\"
fn parseModulesFolder =
(
modules = getFiles (sourceFolder + modulesFolder + "*.ms")
for i in modules do
(
moduleName = i as string
include moduleName
)
return modules
)
rollout mainRollout "GenTools" width:184 height:760
(
subRollout toolssub "" pos:[0,56] width:184 height:672
on mainRollout open do
(
modules = parseModulesFolder()
for i in modules do
(
rolloutName = getFilenameFile i
print rolloutName
AdduSubRollout mainRollout.toolssub (execute rolloutName)
)
)
)
createDialog mainRollout style:#(#style_toolwindow, #style_sysmenu, #style_minimizebox)
Now the issue is I get thrown the error
-- Error occurred in anonymous codeblock; filename: C:\Users\MaceWindow\Documents\MaxScript\Testing Grounds\IncludeTest\IncMain.ms; position: 439; line: 19
-- Compile error: include expected filename string
-- In line: include i
The help file and google are saying
"This is a compile-time construct, therefore the file name specification must be a string literal, and not a variable or an expression."
Is there any way around this or am I shafted?
=====
Update to reflect working code
try(destroyDialog mainRollout)catch()
rootFolder = getFileNamePath (getThisScriptFilename())
sourceFolder = rootFolder + "source\\"
modulesFolder = "modules\\"
rollout mainRollout "GenTools" width:184 height:760
(
subRollout toolssub "" pos:[0,56] width:184 height:672
on mainRollout open do
(
modules = getFiles (sourceFolder + modulesFolder + "*.ms")
for i in modules do
(
fileIn i
rolloutName = getFilenameFile i
print rolloutName
AddSubRollout mainRollout.toolssub (execute rolloutName)
)
)
)
--clearlistener()
createDialog mainRollout style:#(#style_toolwindow, #style_sysmenu, #style_minimizebox)
FileIn works perfectly as detailed below by Monster with the addition of an exectue before the file name. As I'm executing all the code contained in the other maxscript files straight away there's no benefit to Including over FileIn
Replies
fileIn is run in a global context so the rollout definition will be global.
Example Module File:
which is not the correct format of a filename.
Should be either http://docs.autodesk.com/3DSMAX/15/ENU/MAXScript-Help/index.html?url=files/GUID-7F17449E-C377-445C-AC15-CD3BA88A975B.htm,topicNumber=d30e141051
edit: ok, i was wrong. In fact the include happens before executing, so you just can't include your file through a variable.
You are right, but the problem in this case is that the parameter given to the include command cannot be a variable. Include's only intended use is to break up large files.
http://docs.autodesk.com/3DSMAX/16/ENU/MAXScript-Help/files/GUID-1CF90959-B604-45F9-8552-7680F535BF50.htm
the only thing I had the change from your code was adding execute on the string.
Thanks for the help!