Subscribe Bookmark RSS Feed

data filter for loop

vishwasanj

Frequent Contributor

Joined:

Dec 27, 2016

Hi,

I am fairly new to scripting. I understand for loop but I need a little bit of help here.

I am not able to find the for loop example for a data filter in the scripting guide. If someone could help me with the syntax, that would be great.

 

What I am trying to do is, I have a treemap and I need to construct a 'for' loop with the data filter table to get the graph outputs saved as .png file automatically.

 

I have attached a figure. For example, condition 1: wafer 11, choosing all Vpp trimset for 25C and Formula NO (1 graph)

                                                               condition 2: wafer 12, choosing all Vpp trimset for for 85C (0,11111)and  and Formula NO (1 graph)

                                                               condition 3: plotting each trimset value for all for wafer 11( 9 graphs) and wafer 12 with YES (2 graphs)

I am able to do it if I do it one by one in a code, but not together.

 

Thank you

1 ACCEPTED SOLUTION

Accepted Solutions
David_Burnham

Super User

Joined:

Jul 13, 2011

Solution

The example I give below contains code that will skip combinations for which there are no rows

 

http://www.pega-analytics.co.uk/blog/scripting-data-filters/

 

 

-Dave
13 REPLIES
M_Anderson

Staff

Joined:

Nov 21, 2014

You might try @Craige_Hales response in this question- link.  Rather than trying to work with the local data filter, adding a where clause into your platform call is probably a more elegant way to do what you're after.

vishwasanj

Frequent Contributor

Joined:

Dec 27, 2016

I belive that example was for a fit y by x distribution. I am trying to do it for a treemap in graph builder. I will give it a shot. Thank you M_Anderson

M_Anderson

Staff

Joined:

Nov 21, 2014

It is, but graph builder also accepts where clauses.

Best,

M
Craige_Hales

Staff

Joined:

Mar 21, 2013

dt = Open( "$sample_data/big class.jmp" );
ages = Data Table( "big class" ) << Summary( Group( :age ), Freq( "None" ), Weight( "None" ) );
sexes = Data Table( "big class" ) << Summary( Group( :sex ), Freq( "None" ), Weight( "None" ) );
Delete Directory( "$temp/myPics" );
Create Directory( "$temp/myPics" );
For( iage = 1, iage <= N Rows( ages ), iage++,
thisAge = ages:age[iage];
For( isex = 1, isex <= N Rows( sexes ), isex++,
thisSex = sexes:sex[isex];
Eval(
Eval Expr(
gb = dt << Graph Builder(
Size( 508, 438 ),
Show Control Panel( 0 ),
Variables( X( :weight ), Y( :height ) ),
Elements( Points( X, Y, Legend( 5 ) ) ),
where( age == Expr( thisAge ) & sex == Expr( thisSex ) )
)
)
);
parentBox = (Report( gb ) << parent)<<parent;
picture = parentBox << getpicture;
picture << saveImage( "$temp/myPics/age" || Char( thisAge ) || "sex" || Char( thisSex ) || ".png", "png" );
// optional: Open( "$temp/myPics/age" || Char( thisAge ) || "sex" || Char( thisSex ) || ".png" );
gb << closewindow;
);
);
Close( ages, "nosave" );
Close( sexes, "nosave" );
Show( Files In Directory( "$temp/myPics" ) );

It looks like you might need to grab the "grandparent" displaybox for graph builder; the parent)<<parent does that to reach out to the where clause in the display tree.

screen capture of large icons of graphs saved by scriptscreen capture of large icons of graphs saved by script

 

Craige
vishwasanj

Frequent Contributor

Joined:

Dec 27, 2016

Thank you Craige
vishwasanj

Frequent Contributor

Joined:

Dec 27, 2016

Hi Craige,

I did implement and I started expaning on the for loops.

I got this error, Send Expects Scriptable Object{630} in access or evaluation of 'Send' , Report( gb ) << /*###*/parent/*###*/... Is it because there are too many windows open and JSL doesn't realize which gb I am referring to?
txnelson

Super User

Joined:

Jun 22, 2012

From your comment I believe that you have a misunderstanding of Craig's script that he posted.  In his code, there is never more than 1 instance of the graph builder open at a time. The pointer to the graph builder, "gb" points to the current execution of the graph builder.  It creates a picture object of the Graph Builder output, saves it to a file.  Then it CLOSES the graph builder object (gb<<closewindow) and then loops back and starts all over again,

 

If your code is generating multile graph builders, and each one uses "gb" as the handle pointing to the graph builder instance, "gb" is only pointing to the last graph builder instance.

Jim
Craige_Hales

Staff

Joined:

Mar 21, 2013

right.  or gb was never set, or gb is already closed.

You can use 

 show(type(gb));
showproperties(gb);

in your script to get some information about the object.  You should see something like this in the log:

Type(gb) = "Scriptable";
Show Control Panel [Boolean] [Default On] (Displays or hides the control panel.)
Show Legend [Boolean] [Default On] (Displays or hides the legend to the right of the graph.)
Legend Position [Enum] {Right, Bottom, Inside Left, Inside Right}
Legend Settings [Action](Opens a dialog to modify the properties of the legend.)
Continuous Color Theme [Action](Se .... < a lot more follows>

In JMP, a "scriptable" object is an object like a DisplayBox or a platform (or a lot of other possibilities) that has methods.  A DisplayBox has a method named parent that is used with the << operator to get the DisplayBox's parent box.  The ShowProperties function lists all the methods the DisplayBox knows about.  You can see these in the scripting index (under the help menu) in an easier to read form.

When your script says "expecting a scriptable..." it means the gb variable does not hold a scriptable object.

 

 

Craige
Craige_Hales

Staff

Joined:

Mar 21, 2013

and in the example code, gb is a platform object.  the report() function asks the platform object for the DisplayBox that holds the platform's visible report.  The platform is unaware that there are more DisplayBoxes around it.  You have to use the <<parent method, twice, to navigate up to the DisplayBox that holds the where clause.

Craige