Home Technical Talk

Maxscript, including external files problem

polycounter lvl 9
Offline / Send Message
Dickie polycounter lvl 9
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

Sign In or Register to comment.