cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
Choose Language Hide Translation Bar
martin_snogdahl
Level III

Add script to ButtonBox in jmp report

 

Dear community

I think my problem is a simple one, but all the same I could use some help. I am using the profiler platform with the added simulator to create a monte carlo simulation of a response with several factors:

 

MyProfiler = Profiler(

Y( :Response)

);

MyProfiler << Simulator(

Factors(

   Factor 1 << Random(Normal()),

   Factor 2 << Random(Normal())

);

 

I want to add some functionality to the ‘Make Table’ button under the ‘Simulate to Table’ outline box in the report window. I do that by adding a script. What I want to do is name the table resulting from the ‘Make Table’ button and perform a series of operations on this table:

Report(MyProfiler)[ButtonBox(2)] << Set Script(

MySimTable = Current Data Table();

        //Perform actions on MySimTable

);

The problem is that the ‘Current Data Table' command is executed before any other actions when pressing the button. This means that the current table is not the table generated by pressing the ‘Make Table’ button. So here is my question: Is there a way to perform the ‘build in’ button function before running the ‘Current Data Table’ command? Any solutions giving me a reference to the generated table automatically will be much appreciated.

Thank you

5 REPLIES 5
ian_jmp
Level X

Re: Add script to ButtonBox in jmp report

I think the script below just confirms the behaviour you have found. It looks like, in such cases, 'setScript' adds to the predefined script (which seems reasonable), but it appears to prepend rather than append:

NamesDefaultToHere(1);

// Test table

dt = New Table( "Simulate",

Add Rows( 5 ),

New Column( "x",

Numeric,

"Continuous",

Format( "Best", 12 ),

Set Values( [1, 2, 3, 4, 5] )

),

New Column( "y",

Numeric,

"Continuous",

Format( "Best", 12 ),

Formula( :x + Random Normal( 0, 0.1 ) )

)

);

// Fit Model

fm = dt << Fit Model(

Y( :y ),

Effects( :x ),

Personality( "Standard Least Squares" ),

Emphasis( "Effect Leverage" ),

Run(

Profiler(

1,

Confidence Intervals( 1 ),

Term Value( x( 3, Lock( 0 ), Show( 1 ) ) ),

Simulator(

1,

Factors( x << Random( Normal( 3, 0.8 ) ) ),

Responses( y << No Noise )

)

),

:y << {Lack of Fit( 0 ), Plot Actual by Predicted( 1 ), Plot Residual by Predicted( 1 ), Plot Effect Leverage( 1 )}

)

);

//  Define a sample script

doSomething =

Expr(

Beep();

For(i=1, i<=NTable(), i++, Print(i, DataTable(i) << getName));

);

// Assign the sample script to the button (JMP seems to prepend to the script that's already there?)

Report(fm)[ButtonBox(5)] << setScript(doSomething);


Maybe send this thread to support@jmp.com to get a definitive answer?

martin_snogdahl
Level III

Re: Add script to ButtonBox in jmp report

Hi Ian

Thanks for your reply. I've send this discussion to the support team, just to see what they might have to say.

jerry_cooper
Staff (Retired)

Re: Add script to ButtonBox in jmp report

I agree with Ian. However, as a workaround until you get a better option, you might consider adding a new button that hijacks the Make Table functionality:

 

Report(MyProfiler)["Simulate to Table"] << Prepend(

 

     newbutton = Button Box( "Make Table Plus",

 

     Report(MyProfiler)[ButtonBox(3)] << Click();

 

     MySimTable = Current Data Table();

 

     )

 

);

 

Note that inserting the new button changes the reference to the original Make Table button from 2 to 3.

martin_snogdahl
Level III

Re: Add script to ButtonBox in jmp report

Hi Jerry

I had a similar idea for a workaround. Thanks for showing me how to implement this solution. It works perfectly

Re: Add script to ButtonBox in jmp report

Hello,

I have confirmed with the JMP Development team that it is intentional behavior for the script to be run before the built-in functionality is executed.

Below is a simplified example that demonstrates how you can hide the original button, run a script, click the original (hidden) button, and then run another bit of script. 

dt = Open( "$SAMPLE_DATA/Big Class.jmp" );

dt << New Column( "heightplusweight", Formula( :height + :weight ) );

// replace the button in Simulate To Table

x = Profiler( y( :heightplusweight ) );

x << Simulator(

  Factors( Factor1 << Random( Normal() ), Factor2 << Random( Normal() ) )

);

bb2 = Report( x )["Simulate to Table"][Button Box( 1 )];

bb2 << Visibility( "Hidden" ); // new for JMP 12

bb2 << Sib Prepend(

  Button Box( "NewButton",

    setfunction(

      Function( {this}, // this==replacement button

        New Window( "Before",

          <<Modal,

          H List Box( Button Box( "OK" ), Button Box( "Cancel" ) )

        );

        (this << Sib) << Click; // sib==original button because of <<sibprepend

        New Window( "After",

          <<Modal,

          H List Box( Button Box( "OK" ), Button Box( "Cancel" ) )

        );

  )

  )

  )

);

Using this as a model, you can apply the concept to hide and click the old button and then set the name of the new table:


bb2 << Sib Prepend(

  Button Box( "NewButton",

  setfunction(

    Function( {this}, // this==replacement button

      (this << Sib) << Click; // sib==original button because of <<sibprepend

      Data Table(1) << Set Name( "New Table Name" );

  )

  )

  )

);


I hope this helps.


Wendy

Wendy