Notifications
Clear all

[Closed] external scripts via fileIn trouble

Hi

I’m currently working on an fbx exporter ui which uses different “export scripts” that clean up the scene and then export the objects / entire scene. So all the magic is handled by the external export scripts.

What would be the proper way to connect the main ui script with external export scripts? So I can pass variables (export path, ui settings) and run it instantly? As the user can select different export scripts I can’t include the scripts directly.

Calling a function in the export script and passing variables works only the second time, when the functions have been evaluated already…

thanks in advance,
Max.

4 Replies
1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

here is a sample how to organize interface between main UI (rollout, dialog, etc.) and loaded external scripts;


 global scriptData
 struct commonData 
 (
 	a, b, c, 
 	-- functions:
 	fnA, fnB, fnC
 )
 try(destroyDialog Script_Rol) catch()
 rollout Script_Rol "Scripts" width:200
 (
 	
 	spinner com_sp "Value: " fieldwidth:40 type:#integer range:[0,1e9,0]
 	button a_bt "A" width:55 across:3 
 	button b_bt "AB" width:55  
 	button c_bt "ABC" width:55
 	
 	on a_bt pressed do if isStruct scriptData and iskindof scriptData.fnA MAXScriptFunction do scriptData.fnA() 
 	on b_bt pressed do if isStruct scriptData and iskindof scriptData.fnB MAXScriptFunction do scriptData.fnB() 
 	on c_bt pressed do if isStruct scriptData and iskindof scriptData.fnC MAXScriptFunction do scriptData.fnC() 
 	
 	button load_bt "Load Script" width:171 offset:[0,6]
 	on load_bt pressed do fileIn "struct_script_01.ms"
 		
 	on Script_Rol open do
 	(
 		scriptData = commonData a:"Hello!" b:com_sp c:Script_Rol
 		fn fnA = format "A:%
" scriptData.a
 		fn fnB = format "A:% B:%
" scriptData.a scriptData.b
 		fn fnC = format "A:% B:% C:%
" scriptData.a scriptData.b scriptData.c
 		scriptData.fnA = fnA
 		scriptData.fnB = fnB
 		scriptData.fnC = fnC
 	)
 )
 createDialog Script_Rol pos:[400,200]
 
 /*
 -- save this part of code as "struct_script_01.ms"
 (
 	if isStruct scriptData do
 	(
 		fn newA = format "NEW A:%
" ::scriptData.a
 		fn newB = 
 		(
 			format "NEW B:%
" ::scriptData.b
 			::scriptData.b.value += 1
 		)
 		fn newC = 
 		(
 			format "NEW C:%
" ::scriptData.c
 			::scriptData.c.com_sp.value = random 0 10000
 		)
 		::scriptData.fnA = newA
 		::scriptData.fnB = newB
 		::scriptData.fnC = newC
 	)
 )
 */
 

the best way is to have some common structure where the Main UI sets parameters (data, controls) and External Scripts set functions (and/or extra data).

play with “A”, “AB”, and “ABC” button before and after the script loading.

do you really need them to be executed in a global scope?
if not why not use include?

I’m not a big fan of having them in global scope either. However I collect the available export scripts from a directory so “everyone” could have custom scripts. (i.E: character export, weapon export … )

So the include wouldn’t work with a variable list.

I didn’t even dare to think of such a way. Elegant solution, thanks alot for the efforts!