Subscribe Bookmark RSS Feed

Script works until it is called upon by an add-in!

gwenicat

Community Trekker

Joined:

Aug 28, 2014

Hello,

I have a script that acquires data from a user interface, runs a fit in JMP and spits out a report with the raw data, some calculated data and various plots and selected info from the JMP output.

It works well when ran from the script, even once encrypted.

However, once I paste the encrypted file into a simple add-in with only this script in, everything works except it no longer display the fit equation I extract from the JMP output.

I'm baffled!

To make things even more baffling, JMP works from the Add-in perfectly as long as I have run the script once from the script window before using the Add-in. Almost as if it now remembers what to do!

The script gets the equation here:

nlr = nlModel << Report;

pb = nlr[PictBox(1)];

modEq = pb << Get Image;

It then displays it using:

V List Box(

  Text Box("Model Equation", << Set Font Size (12)),

  Picture Box( modEq),

  Text Box(" "),

Any idea why just this bit stops working once integrated to the Add-in?

I'm attaching a screen dump of the output ran from script window vs ran from the Add-in (straight after opening JMP)

Thanks

10 REPLIES
erichill

Staff

Joined:

Oct 1, 2013

Hey, Gwenicat,

Are there any messages in the JMP Log?

Most problems of this type tend to come down to variable scoping.  Your add-in is most likely running with Names Default To Here(1), but the script when you run it outside of the context of the add-in is probably running without that.  So, outside the add-in context, your variables are all global, but in the context of the add-in, they are added to the Here namespace instead.  So I think modEq inside the V List Box cannot be found in the add-in version.  The fact that it works when you run the script outside the add-in once first supports this theory, because doing so will put modEq into the global namespace, allowing the add-in script to find it.

Try changing these two lines:

modEq = pb << Get Image;

Picture Box( modEq),

to

::modEq = pb << Get Image;

Picture Box(::modEq),

and see if that doesn't work better.  That assures that modEq gets put into the global namespace.  Or, if you want to keep it in the Here namespace (probably a better practice), do this instead:

Here:modEq = pb << Get Image;

Picture Box( Here:modEq),

Let me know if that fixes it.

Thanks,

Eric

gwenicat

Community Trekker

Joined:

Aug 28, 2014

Hi Eric and thanks for this answer.

When I went away and thought about it, I also remembered the scope issue and realised that must be a problem.

I tried both your solutions and it did not work... first time around.

Now however, if I run the addin twice in a row, the prediction equation is displayed in my second report output. I'm going to try again when I'm not between two meetings!

It's funny how this particular picture box gave me problems and yet other bits I also got out of the jmp report got displayed properly.

Good learning here!

Thanks again :-)

hardner

Community Trekker

Joined:

Nov 13, 2012

Agree this looks like scoping.

But, probably unrelated,  I'm also surprised this works for you:   pb = nlr[PictBox(1)];

if I don't spell out [PictureBox(1)] I get an error.  wonder if that is a JMP version thing.

I was also going to suggest you could add

nlr<<showtreestructure() to troubleshoot that PictureBox(1) is really there with the thing you wanted.

Again probably not relevant to this immediate issue but I would suggest that if your addin is going to pull different data every time (or be used by others with maybe other preferences) you want to make sure that box will always be there and always be PictureBox(1). You might want to seek that more specifically based on the outline box name it's under or test for finding it.  maybe you are already doing the latter since your script doesn't fail but goes on to make the report.  The failure I see with PictBox halts the whole script, it doesn't go on to use a blank instead.

gwenicat

Community Trekker

Joined:

Aug 28, 2014

Hi Hardner and many thanks for your comments.

Thanks for the troubleshooting tip as well. When I initially wrote this, a few months back, the numbers in the tree structure did not match and I ended up having to guess. I had forgotten about this. It was really odd: tree structure would say number box 18, but to get it out and display it in my report window, I'd have to call number box 7 for example!!!

The addin will always perform the same analysis so no issues on that side of things.

Craige_Hales

Staff

Joined:

Mar 21, 2013

PictBox and PictureBox are two distinct boxes.  Internally, JMP uses PictureBox as a marker in a displaybox tree.  That marker is used in a number of ways to help determine when the child boxes should be grouped into a single chunk.  Platforms generally put a PictureBox around a graph and its axes.  That is the point in the tree where you'd often want to "take a picture".

PictBox is a box that holds a bitmap picture.

Unfortunately, the PictureBox() function creates a PictBox.  There is no JSL function to create a PictureBox, but platforms do create them. 

Unless you are adding images to a report, you probably won't find PictBox.  You probably will find PictureBox if there is a graph.

Craige
gwenicat

Community Trekker

Joined:

Aug 28, 2014

Hello,

I've tried a few different scenarios now.

notes

  • the addin and the script both use names default to here clause (mostly in case people use JMP for something else at the same time)
  • the equation I want to import fro the JMP report into mine is a custom one from a column in the table that uses a formula to be populated and I turned on Show Prediction Expression( 1 )
  • in the tree structure, this appears as a pictbox as craige said because equations in JMP are pictures rather than text. And so in my new script I used Eric's suggestion and it's now

nlr = nlModel << Report;

pb = nlr[PictBox(1)];

modEq = pb << Get Image;

  • the script also gets a table:

tb = nlr[TableBox(5)];

tblValues = tb  << Make Into Data Table;


  • it also gets a graph made up of several bits gathered in a picture box:

bb = nlr[PictureBox(1)];

plot = bb << Get Picture;


It displays those without any problems in my own report.


Scenarios:

  • works from script every time
  • works from addin when the script is opened even if it's not been run
  • works if the addin is called upon a second time and the report has not been closed (the report without the equation displayed)
  • does not work when it's called from the addin for the first time or any time if the report window has been closed
  • works if the log is opened
  • works once the log has been opened even if both log and report windows are closed beforehand
  • works as long as any JMP window is opened (JMP addin edit window/any data table/script window) but once those are closed, it no longer works

Looks like my addin needs a friend to work


As you could see from the picture, it's displaying a cross. I should also say that when the script is running, JMP opens its own report window and the tables I scripted to run the non linear fit. Those open and close in the background as I could not figure out a way to make them totally invisible. When that happens I get a glimpse of the JMP analysis report having a cross instead of the prediction equation as well.


If this was for me, I would not mind but I have to validate this for use in cGMP and I cannot very well tell people to run it twice each time to get the correct format!


I'm at a loss here...


Any further thoughts?

Craige_Hales

Staff

Joined:

Mar 21, 2013

Try this:

picturebox(newimage( modEq ))

I think the red X means the pict box is connected to the original data for the image and that data no longer exists.  By cloning the image (with newImage) I think the pict box will have its own private copy.

You might also be able to leave out the picturebox function:

V List Box(

  Text Box("Model Equation", << Set Font Size (12)),

  modEq, // I think the image will work without the PictureBox function, but it might still need newImage

  Text Box(" "),

Craige
gwenicat

Community Trekker

Joined:

Aug 28, 2014

Hi Craige,

Soooo... I tried to use the newimage function (Good one I did not know) and still no luck.

I tried to add it when extracting from the report platform:

nlr = nlModel << Report;

pb = nlr[PictBox(1)];

//modEq = pb << Get Image;

//Here:modEq = pb << Get Image;

modEq = pb << Get Image;

modEq = NewImage(modEq);

I also tried it in my own report window:

V List Box(

  Text Box("Model Equation", << Set Font Size (12)),

  picturebox(newimage( modEq )),

And I tried in both places for good measure!

There is a difference: the background JMP report still shows a cross but my report just shows nothing, not even an empty space.

However, going back through the script and running less and less, I realised that the place where it actually fails is here:

// Data analysis

win3 = New Window( "Non Linear Model Report",

  nlModel = dt << Nonlinear(

  Y( :Name( "hGH" ) ),

  X( :Name( "Model Growth" ) ),

  Second Deriv Method( 1 ),

  Newton,

  Finish,

  Confidence Limits,

  Show Prediction Expression( 1 )

  )

);

win3 gets closed by the script and is replaced by my own report window with everything the scientists asked me for. So for some reason, if there is no window opened in JMP except the home window, the show prediction equation instruction fails! All the tricks that were suggested in this thread concern operations done after the NLR is performed and so they don't affect the outcome.

And the reason I never identified this bug when I wrote the addin a few months back is because I had the tip of the day window on. It must have been enough for the addin to work: any JMP window that's opened seems to do the trick.

For background: hGH is the response and values are entered by the user further up, model growth is the column using the elusive model equation as a formula that takes in time and models the "expected growth" that will be fit against actual growth.

So the problem is that the nonlinear function will not display the pred equation where it's called upon in my script when no other jmp windows are opened.

I create a table earlier:

dt = New Table( "Data",

  private,

  Add Rows( 6 ),

  New Column( "Time", Numeric, Set Values( lstTimes ) ),

  New Column( "hGH", Numeric, Set Values( lsthGH ) )

);

I took the private instruction out and of course now the addin works.

But the reason I used private is because it was the only way my output would work. If I try to close the data table at the end, even with wait, the report is not produced.

Anyway, it's not a proper solution but if there was a way to have the data table open when the report is produced so there is no glitch and then close the data table without the script failing, I'd settle for that.

I wonder if it will work in JMP 13, if it's a bug or if there is actually is a mistake somewhere in the way I scripted...

gwenicat

Community Trekker

Joined:

Aug 28, 2014

I've had to use an unsightly workaround in order to be able to run my validation tests: just before calling out the non linear JMP analysis, I open an empty window and I close it at the end of the script.

It works. I expect show then hide log would work as well.

I'm aching to understand why it is doing this though!