Loss of handle to graph builder windowI am using the baseball.jmp script to illustrate an issue I am seeing in my own script. The following runs as expected. A single graph builder window is created, and closes after two seconds.
Clear Globals();
Names Default To Here( 1 );
dt = Open( "C:\Program Files\SAS\JMP\14\Samples\Data\Baseball.jmp" );
current data table(dt);
myGraph = Graph Builder(
Size( 531, 448 ),
Show Control Panel( 0 ),
Variables( X( :Player ), Y( :Batting ) ),
Elements( Points( X, Y, Legend( 2 ) ) ),
);
myRep = myGraph << report;
wait(2);
myGraph << close window;
However, I am trying to build up a graph builder expression in a function to make it more flexible. So in the following example, consider myExpr as the constructed expression. Note that the 2 second delays are so I can figure out when the windows get created.
Clear Globals();
Names Default To Here( 1 );
dt = Open( "C:\Program Files\SAS\JMP\14\Samples\Data\Baseball.jmp" );
current data table(dt);
myExpr = expr(Graph Builder(
Size( 531, 448 ),
Show Control Panel( 0 ),
Variables( X( :Player ), Y( :Batting ) ),
Elements( Points( X, Y, Legend( 2 ) ) ),
));
myExpr1 = expr(myGraph = eval expr(myExpr));
eval(myExpr1);
wait(2);
myRep = myGraph << report;
wait(2);
myGraph << close window;
The following happens that does not make sense to me:
- A second and identical graph builder window opens when the report layer is created.
- The myGraph handle that was working when creating the report layer, does not work when running myGraph << close window. This leaves two graph builder windows open.
I am able to close the unexpected second window with myRep << close window, but am not able to close the myGraph window. I am able to manipulate the report layer as usual.
So my questions are:
- Why does a second graph builder window get created?
- Why am I losing the myGraph handle?
Thanks,
Bill
Re: Loss of handle to graph builder windowYour 2 questions are best answered in reverse order:
- Why does a second graph builder window get created?
- Why am I losing the myGraph handle?
2. If you look at what the value of myGraph is after
eval(myExpr1);
you will see that the variable is not set to pointing to the Graph Builder object, but is rather just defined as the JSL required to run the Graph Builder
Graph Builder(Size(531, 448), Show Control Panel(0), Variables(X(:Player), Y(:Batting)), Elements(Points(X, Y, Legend(2))));
What you need to do is to move it to the myExpr expression. Then it will point to the Graph Builder object as you want.
1. The reason you are getting two windows displayed, is that when you specify
eval(myExpr1);
it executes the value of myGraph, which is a line of JSL that creates a window with the output, and then again, when the variable myGraph is parsed in
myRep = myGraph << report;
it will execute the JSL from the variable myGraph once again
Below is my reworking of your code to do what I believe you want to do
Clear Globals();
Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA\Baseball.jmp" );
current data table(dt);
myExpr = expr(myGraph = Graph Builder(
Size( 531, 448 ),
Show Control Panel( 0 ),
Variables( X( :Player ), Y( :Batting ) ),
Elements( Points( X, Y, Legend( 2 ) ) ),
));
myExpr1 = expr(eval expr(myExpr));
eval(myExpr1);
wait(2);
myRep = myGraph << report;
wait(2);
myGraph << close window;
Re: Loss of handle to graph builder windowHi Jim,
Thank you for the explanation. Just when I thought I was starting to understand JSL expressions....
Anyway building the expression: expr(graph builder(insert my stuff here)) is easier than building the expession: expr(myGraph = graph builder(insert my stuff here))
That is why I took that approach.
Thanks Again,
Bill