cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
Choose Language Hide Translation Bar
CoverChikaka
Level I

Direct passing argument to a script file

Hey,
 
i wish to pass argument str1, a string argument to a separate script named: "script2run.jsl" for example, nad that script uses str1 argument and print a message such as :
print("This is the important string I successfully passed: " || Eval(str1)) ;
 
a different script that create a window that will be saved as journal for later usage will triger that script through buttons that would be something like this:
vars4script = {"nine", "one", "two", "eight", "eleven"}; 

win_click = New Window( "journal window",
	Spacer Box( size( 100, 10 ) ),
	Header = Text Box( " journal window buttons", <<Font Color( " Blue" ) ),
	Panel Box( " buttons1 ", buttons_area1 = H List Box() ),
	Panel Box( " buttons2 ", buttons_area2 = H List Box() ),
	Panel Box( " buttons2 ", buttons_area3 = H List Box() ), 

);

//Method 1
For( i = N Items( vars4script ), i, i--,
	str1 = vars4script[i];
	buttons_area1 << Append( Button Box( Eval( str1 ), Include( "script2run.jsl", Eval( str1 ) ) ) );
);

//Method 2
For( i = N Items( vars4script ), i, i--,
	str1 = vars4script[i];
	buttons_area2 << Append(
		Button Box( Eval( str1 ), <<Set Function( Expr( Include( "script2run.jsl", Eval( str1 ) ) ) ) )
	);
);

//Method 3
For( i = N Items( vars4script ), i, i--,
	str1 = vars4script[i];
	buttons_area3 << Append( Button Box( str1, Eval Expr( "include('script2run.jsl', '$str1')" ) ) );
);
there are 3 methods here but none is working properly when buttons are clicked
4 REPLIES 4
ErraticAttack
Level VI

Re: Direct passing argument to a script file

Is there a reason you need to do it this way?  Unless you're constrained from some sort of extreme circumstances, your method of constructing an interactive GUI is not what you should be doing.

 

Consider using JMP classes -- these allow you to use methods directly as the callbacks on display elements and can greatly simplify GUI construction.

Jordan
jthi
Super User

Re: Direct passing argument to a script file

I consider building your UI in some other way, but if you really want to go the way you have suggested, this might work (I would not use this)

Names Default To Here(1);

vars4script = {"nine", "one", "two", "eight", "eleven"}; 

win_click = New Window("journal window",
	Spacer Box(size(100, 10)),
	Header = Text Box(" journal window buttons", <<Font Color(" Blue")),
	Panel Box(" buttons1 ", buttons_area1 = H List Box()),
	Panel Box(" buttons2 ", buttons_area2 = H List Box()),
	Panel Box(" buttons2 ", buttons_area3 = H List Box()), 
);

For(i = N Items(vars4script), i >= 1, i--,
	Eval(EvalExpr(
		buttons_area1 << Append(Button Box(vars4script[i], 
			str1 = Expr(vars4script[i]);
			Expr(Parse(Load Text File("script2.jsl")));
		));
	));
);
-Jarmo
CoverChikaka
Level I

Re: Direct passing argument to a script file

If you can give examples of better ways I'll be more than happy to see. my only constraints are that one generic script will get different variable depending on the button clicked in the UI.
jthi
Super User

Re: Direct passing argument to a script file

In simple cases, you could most likely use a function and maybe button name as argument. Can you modify your generic script? Could it for example be included at the beginning of your script and then you call a function from that generic script within each of the buttons?

 

script1.jsl

Names Default To Here(1);

Include("script2.jsl");

vars4script = {"nine", "one", "two", "eight", "eleven"}; 

win_click = New Window("journal window",
	Spacer Box(size(100, 10)),
	Header = Text Box(" journal window buttons", <<Font Color(" Blue")),
	Panel Box(" buttons1 ", buttons_area1 = H List Box()),
);

buttons_area1 << Append(
	Button Box("nine", << Set Function(function({this},
		my_func((this << Get Button Name));
	)));
);
buttons_area1 << Append(
	Button Box("one", << Set Function(function({this},
		my_func((this << Get Button Name));
	)));
);

script2.jsl

Names Default To Here(1);

my_func = function({str}, {Default Local},
	Show(str);
);

 

-Jarmo