cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Browse apps to extend the software in the new JMP Marketplace
Choose Language Hide Translation Bar
gpuckett
Level I

Issue running JSL files in C#.NET

I am trying to execute JSL files in a C#.NET wrapper. I am able to sucessfully run the files but my code does not wait for the script to finish. Below is a sample:

JMP.Application jmpInstance = new JMP.Application();

FileInfo fJSLFile = new FileInfo(@"C:\Test\Test.JSL");

jmpInstance.RunJSLFile(fJSLFile.ToString());                       

if (jmpInstance.HasRunCommandErrorString())

{

     throw new ApplicationException("Error with JMP script: " + jmpInstance.GetRunCommandErrorString());

}

4 REPLIES 4
uday_guntupalli
Level VIII

Re: Issue running JSL files in C#.NET

@gpuckett
       Were you able to figure this out ? I am looking to run JSL functions by passsing parameters to it from C#. Wondering if you could share any insight ? 

 

 

Best
Uday
ChrisM_X
Level III

Re: Issue running JSL files in C#.NET

I use myJMP.RunCommand(command); to pass data to JMP for C#, where command is a string you build up in C# to set up variables.
example
JMP.Application myJMP = new JMP.Application();
string command = "a=1";
myJMP.RunCommand(command);


Example code snippet below:
Below I set spec limits properties on columns that have specs:

JMP.Application myJMP = new JMP.Application();


foreach (var item in Specs)
{
bool setprops = false;
StringBuilder SpecList = new StringBuilder();
if (item.Value.LowerSpec.ToLower() != "nan")
{
SpecList.Append("LSL(Expr(" + item.Value.LowerSpec.ToLower() + ")),");
setprops = true;
}
if (item.Value.UpperSpec.ToLower() != "nan")
{
SpecList.Append("USL(Expr(" + item.Value.UpperSpec.ToLower() + ")),");
setprops = true;
}
// SpecList.Length--; //removes last characther from SB (ending comma)
if (setprops)
{
command = @"Eval(
Eval Expr(" +
"column(dts, Expr(\"" + item.Key + "\")) << set property(" +
"\"spec limits\"," +
" {" + SpecList.ToString() + " Show Limits( 1 )}" +
@"))
); ";

myJMP.RunCommand(command);
}

}
uday_guntupalli
Level VIII

Re: Issue running JSL files in C#.NET

@ChrisM_X

  Thank you for the snippet. I am trying to understand, where in your snippet are you invoking a function ? 

TestPower = function({base,expn},{default local},
			res = base ^ expn ; 
			Retrun(res); 
	            );

Let us assume we have a user defined function in JMP like the one shown above. Now, starting from C#, how can I invoke this function by passing it parameters for base and exp and run this function ? 
The snippet you shared addresses the part about how we can use the RunCommand function to pass a value, but can you use a simple example like this to explain the process a little more in detail ? 
So, if i have the above function stored as TestPower.jsl on my C:\ , can you kindly share on how I would be able to run using C#, by passing it the parameters and calling this function ?

Best
Uday
uday_guntupalli
Level VIII

Re: Issue running JSL files in C#.NET

@ChrisM_X,
        I actually managed to get it to run using your suggestion and a little luck of playing around. Here is my C# code that works. 

            // Create an instance of JMP and make it visible
            JMP.Application MyJMP; 
            MyJMP = new JMP.Application(); 
            MyJMP.Visible = true;
            MyJMP.ShowStartupWindow();
            MyJMP.EnableInteractiveMode(true);

            // create command 
            string arg1 = "base = 2"; // arguments to my User defined function in JSL 
            string arg2 = "expn = 3"; // arguments to my User defined function in JSL 
            MyJMP.RunCommand(arg1);  
            MyJMP.RunCommand(arg2);
            string FilePathOfFileToRun = "C:\\Test.jsl";
            MyJMP.RunJSLFile(FilePathOfFileToRun); // Running the user defined function 

            // Needed to keep JMP from automatically closing
            JMP.DataTable dt = MyJMP.NewDataTable("test");
            MyJMP.RunCommand(@"Close(Data Table(""test""), NoSave)");

 

 

Best
Uday