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

Calling Built-in JMP menu Functions Within Script

Hi Everyone,

 

Inexperienced JSL scripter here. Apologies if this is a trivial question, but I was wondering if there was a way to insert into a variable the scatterplot 3D command for a particular rotation angle (predetermined by the user's rotation of the 3D graph generated by doing scatterplot 3D manually) from within a JSL script. For example,

sp = Scatterplot 3D(
	Y( :age, :height, :weight ),
	Frame3D( Set Grab Handles( 0 ), Set Rotation( -54, 0, 38 ) )
);

, but the idea is to be able to do this without manually copy-pasting the rotation values into the code, as I'm trying to automate a process that requires as input the rotation values from an already-generated Scatterplot. The end goal is to have a script that takes the predetermined rotation values as input and interfaces with an R script (already written) to generate a 2D plot from the 3D scatterplot.This would allow me to circumnavigate the inconvenience of working with the Mac clipboard.

 

Any help is appreciated, thank you.

4 REPLIES 4
akfence
Level II

Re: Calling Built-in JMP menu Functions Within Script

As a followup to this, is there a way to insert the currently open scatterplot into a variable?

txnelson
Super User

Re: Calling Built-in JMP menu Functions Within Script

This discussion question seems to be related to, or the same question as the previous discussion Select rotation and data columns from 3D scatterplot plot script 

To answer the specific question from this post, Your script

sp = Scatterplot 3D(
	Y( :age, :height, :weight ),
	Frame3D( Set Grab Handles( 0 ), Set Rotation( -54, 0, 38 ) )
);

when run, generates a output display object which can be accessed in JSL by creating a variable to point to the object

spr = report( sp );
//or
spr = sp << report;

 "spr" does not contain the scatter plot, but rather is a pointer to the top object within the Output Display Tree that contains the scatter plot and the various objects associated with the output display.

Below is the script I wrote for the above referenced Discussion Question.  In it, it allows the user to run a Scatter Plot 3D, and when the scatter plot is closed, it goes into the display tree and extracts the JMP script that if run, would regenerate the Scatter Plot 3D, just as it was when it was closed.  The script then goes on and extracts out the columns for the 3 axes and the rotation values, into 2 JMP lists called  varsList and rotationList, respectively.  From there, it adds those values back to the original JMP data table as new columns, and then saves the data table as a csv file.

Not knowing what the format of what you need in your csv file to pass to R, this was just a guess of what is needed.

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA\big class.jmp" );
sp = Scatterplot 3D(
	Y( :age, :height, :weight ),
	Frame3D( Set Grab Handles( 0 ), Set Rotation( -54, 0, 38 ) )
);
sp << on close(
	theScript = Char( (Report( sp ) << get scriptable object) << get script );
	varsList = {};
	Insert Into( varsList, Word( 2, Substr( theScript, Contains( theScript, "Y(" ) ), ":," ) );
	Insert Into( varsList, Word( 4, Substr( theScript, Contains( theScript, "Y(" ) ), ":," ) );
	Insert Into( varsList, Word( 6, Substr( theScript, Contains( theScript, "Y(" ) ), ":,)" ) );
	rotationList = {};
	Insert Into( rotationList, Word( 2, Substr( theScript, Contains( theScript, "Rotation(" ) ), "()," ) );
	Insert Into( rotationList, Word( 3, Substr( theScript, Contains( theScript, "Rotation(" ) ), "()," ) );
	Insert Into( rotationList, Word( 4, Substr( theScript, Contains( theScript, "Rotation(" ) ), "()," ) );
	dtSub = dt << subset( columns( Eval( varsList ) ), selected rows( 0 ) );
	dtSub << New Column( "_Vars_", character, set values( varsList ) );
	dtSub << New Column( "_Rotation_", character, set values( rotationList ) );
	dtSub << Save( "$TEMP/passvalues.csv" );
	close( dtSub, nosave );
);

// This line opens the csv back into JMP 
//open("$TEMP/passvalues.csv");

As a note of how JMP works, one cannot place the scatter plot into a variable, and then pass it to R or save it as a .csv file.  However, one can extract the image of the scatter plot at save the image to an image file, or pass the image as a blob.  I don't exactly know what you are looking for.  You may want to look into JMP automation, which would allow you to call R from JMP and for you to pass the information you need directly from JMP to R.

Please get back to the community with more specifics of exactly what you need and we will make an attempt to help you solve the issues.

Finally, I strongly encourage you to take the time to read the Scripting Guide for JMP/JSL that can be found in the JMP Documentation Library under the Help pull down menu.

Jim
akfence
Level II

Re: Calling Built-in JMP menu Functions Within Script

Thank you for the helpful advice. Will attempt to integrate this into my solution. This makes sense. My only concern with this JSL is that, for each new dataset, I would have to manually type out 3 new column names ( :age, etc...) for each new dataset I want to run my script on, which in my case would defeat the purpose of automating this process.
txnelson
Super User

Re: Calling Built-in JMP menu Functions Within Script

I think there is an expectation mismatch.  The purpose of the Discussion Group in the JMP Community is not to provide completed solutions upon the request of JMP users.  The script I provided needs to be looked upon as an illustration of one way to approach the problem.   A learning tool for the user to take an expand on  into their final solution.

Now to address the issue of the last entry, how do you envision the JMP user running the script you are wanting?  How will they choose what columns to use in the scatterplot?

If the plan is to have the user just run a Scatterplot 3D and then when they get the plot to the point they want it to be, and then run a script to strip off the script and get the columns and rotations, here is a piece of JSL that finds the Scatterplot window and then taking code from my last entry, creates a csv file

Names Default To Here( 1 );

// Find the current report
curReport = Current Report();
// Check to see if the JMP current report is actually the Scatterplot 3D report
If( curReport[Outline Box( 1 )] << get title == "Scatterplot 3D",
	theScript = Char( (xx[Outline Box( 1 )] << get scriptable object) << get script );
	dt = Current Data Table();
,
	// If not, find the window that is the 3D plot
	i = 1;
	While( Try( Window( i )[Outline Box( 1 )] << get title, "" ) != "Scatterplot 3D" & i < 100, i++ );
	If( i < 100,
		curReport = Window( i )[Outline Box( 1 )];
		theScript = Char( (curReport[Outline Box( 1 )] << get scriptable object) << get script );
		dt = Data Table( Trim( Word( 1, Window( i ) << get window title, "-" ) ) );
	,
		// If no Scatterplot 3D is jound, display an error
		Dialog( "Error:  No Scatterplot 3D was found" );
		Throw();
	);
);

// If the code makes it to here, strip off the script components needed
varsList = {};
Insert Into( varsList, Word( 2, Substr( theScript, Contains( theScript, "Y(" ) ), ":," ) );
Insert Into( varsList, Word( 4, Substr( theScript, Contains( theScript, "Y(" ) ), ":," ) );
Insert Into( varsList, Word( 6, Substr( theScript, Contains( theScript, "Y(" ) ), ":,)" ) );
rotationList = {};
Insert Into( rotationList, Word( 2, Substr( theScript, Contains( theScript, "Rotation(" ) ), "()," ) );
Insert Into( rotationList, Word( 3, Substr( theScript, Contains( theScript, "Rotation(" ) ), "()," ) );
Insert Into( rotationList, Word( 4, Substr( theScript, Contains( theScript, "Rotation(" ) ), "()," ) );

// Add the columns used and the rotations to a new data table
dtSub = dt << subset( columns( Eval( varsList ) ), selected rows( 0 ) );
dtSub << New Column( "_Vars_", character, set values( varsList ) );
dtSub << New Column( "_Rotation_", character, set values( rotationList ) );
dtSub << Save( "$TEMP/passvalues.csv" );
Close( dtSub, nosave );

 

Jim