cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
Dyan
Level I

How to add a button to open a script in another folder.

Hi all, how can i make it such that whenever i click a button i placed in a journal it will run the script that is located in another folder.

Using a test script below i am able to successfully open script in another folder. This is on JMP16.

 

Names Default To Here( 1 );
Clear Log();

Dir = Get Default Directory();

file_name = "JMP script/Load_PD.jsl";

file_path = Char(Dir || file_name);

Open(file_path);

Using the test scrip i made i tried to implement it to my main script as shown below.

 

The script shown below is just a snippet.

 

LoadTableType = Function( {reportType}, 
	Dir = Get Default Directory();
	If(
		reportType == "PD",
		file_name = "JMP script/Load_PD.jsl";
		file_path = Char(Dir || file_name);
		show(file_path);
		Current Journal() << Append( Button Box("Load PD Table", Open (file_path))),
	);
);

However after the main code finishes running and the button is generated, each time i click the button i keep getting this error shown below:

 

 

Name Unresolved: file_path in access or evaluation of 'file_path' , file_path/*###*/

Would greatly appreciate any advice given thank you!

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
ErraticAttack
Level VI

Re: How to add a button to open a script in another folder.

You've got a button box that has an attached script -- Open( file_path ).  Think of that script as a piece of paper.  Now think of clicking on the button as starting a new blank-slate JMP instance.  In this new instance, you ask it to run the script that's on this piece of paper.  When running that script, it finds the name file_path and does a name-lookup.  Being a complete blank-state, it cannot determine what file_path is supposed to mean, so it throws an error.

 

Clearly this is not exactly what happens, but it is the case that when the button is clicked the attached script is run in a scope that is not the same scope as when you created the button.  This is true for all display box scripts.  They won't know anything about the scope / variables that were present when the display box was created -- the attached scripts / functions run in a new completely separate scope.

 

An easy fix is to use Eval( Eval Expr( ... Expr( ... ) ... ) ), like this:

LoadTableType = Function( {reportType}, 
	Dir = Get Default Directory();
	If(
		reportType == "PD",
		file_name = "JMP script/Load_PD.jsl";
		file_path = Char(Dir || file_name);
		Eval( Eval Expr(
			Current Journal() << Append( Button Box( "Load PD Table", Open( Expr( file_path ) ) ) )
		) )
	);
);

this pre-evaluates the name file_path so that the script doesn't see a name but rather a string with the correct path.

Jordan

View solution in original post

3 REPLIES 3
Byron_JMP
Staff

Re: How to add a button to open a script in another folder.

this might help: try using "include" instead of "open".

 

Names Default To Here( 1 );

dir=Get Path Variable( "SAMPLE_SCRIPTS" );
file_name = "chaosGame.jsl";
file_path = Char(Dir || file_name);
show(file_path);
Current Journal() << Append( Button Box("Chaos Game", include (file_path)))
JMP Systems Engineer, Health and Life Sciences (Pharma)
Dyan
Level I

Re: How to add a button to open a script in another folder.

Hi @Byron_JMP  Thanks for your suggestion but i am still getting the same error 

Name Unresolved: file_path in access or evaluation of 'file_path' , file_path/*###*/
ErraticAttack
Level VI

Re: How to add a button to open a script in another folder.

You've got a button box that has an attached script -- Open( file_path ).  Think of that script as a piece of paper.  Now think of clicking on the button as starting a new blank-slate JMP instance.  In this new instance, you ask it to run the script that's on this piece of paper.  When running that script, it finds the name file_path and does a name-lookup.  Being a complete blank-state, it cannot determine what file_path is supposed to mean, so it throws an error.

 

Clearly this is not exactly what happens, but it is the case that when the button is clicked the attached script is run in a scope that is not the same scope as when you created the button.  This is true for all display box scripts.  They won't know anything about the scope / variables that were present when the display box was created -- the attached scripts / functions run in a new completely separate scope.

 

An easy fix is to use Eval( Eval Expr( ... Expr( ... ) ... ) ), like this:

LoadTableType = Function( {reportType}, 
	Dir = Get Default Directory();
	If(
		reportType == "PD",
		file_name = "JMP script/Load_PD.jsl";
		file_path = Char(Dir || file_name);
		Eval( Eval Expr(
			Current Journal() << Append( Button Box( "Load PD Table", Open( Expr( file_path ) ) ) )
		) )
	);
);

this pre-evaluates the name file_path so that the script doesn't see a name but rather a string with the correct path.

Jordan