JMP Pro 15 Generate Python Code from JournalHi
Was trying to run Generate Python Code from jsl script. It ran fine. When I placed the script in a journal script button the python code was not generated.
I tried the example from the help with the same results.
Am using jmp pro15.
Thanks


Re: JMP Pro 15 Generate Python Code from JournalWorkaround worked fine.
R&D is working on a defect.
Many thanks.
Re: JMP Pro 15 Generate Python Code from JournalApologies. I was testing the code line by line and forgot to do a final test.
If you look carefully you will see that I had commented out the line that generates the Python code, so there was no editor window to capture by title and retrieve the code from. The following script corrects that mistake. I also attached a journal that shows it being executed from a button click.
Thanks for sending this to tech support.
Names Default To Here( 1 );
fd = Formula Depot();
Show(fd);
dt = Open( "$SAMPLE_DATA/Iris.jmp" );
md = dt << Run Script( "Nominal Logistic" );
predictor = md << Publish Probability Formulas;
// Save code to string - doesn't work inside Journals
// py_code = fd << Generate Python Code(Formulas( predictor ), "No Editor");
// just generate to editor instead
fd << Generate Python Code(Formulas( predictor ));
// Get a handle to editor window and retrieve code from it
// Requires the title of the script as argument, which is based on
// model name and data set.
win = Window("Fit_Nominal_Logistic_Species");
py_code = win[scriptbox(1)] << get text;
Save Text File( "$TEMP\logist_J.py", py_code );
Open("$TEMP\logist_J.py");Re: JMP Pro 15 Generate Python Code from JournalThanks.
The work around didn' work either as script window or from a journal. Getting the same error message.
In any event, I opened a ticket at tech support.

Re: JMP Pro 15 Generate Python Code from JournalThanks for checking, @Jeff_Perkinson.
I was also able to reproduce the issue. The "No Editor" option is being ignored when the call to generate python is made from the journal. It is *always* launching a script editor, as it used to do in JMP 13.
Which reminded me of how I used to test this code back then. So I used the same technique to write a workaround for your script. It isn't very pretty, but it might be enough to get you going until we can come up with a fix. In any case, please get in touch with tech support.
Names Default To Here( 1 );
fd = Formula Depot();
Show(fd);
dt = Open( "$SAMPLE_DATA/Iris.jmp" );
md = dt << Run Script( "Nominal Logistic" );
predictor = md << Publish Probability Formulas;
<BR />// Save code to string - doesn't work inside Journals
// py_code = fd << Generate Python Code(Formulas( predictor ), "No Editor");
// Get a handle to editor window and retrieve code from it
// Requires the title of the script as argument, which is based on
// model name and data set.
win = Window("Fit_Nominal_Logistic_Species");
py_code = win[scriptbox(1)] << get text;
Save Text File( "$TEMP\logist_J.py", py_code );
Open("$TEMP\logist_J.py");
Re: JMP Pro 15 Generate Python Code from JournalI was able to reproduce the problem you're seeing just as you suggest, by putting that script in a script button in the Journal.
I think that @nascif_jmp has the best suggestion to contact Tech Support, support@jmp.com. They'll be in the best position to diagnose the problem and recommend a solution.
Post back here with anything you find out from them.
Re: JMP Pro 15 Generate Python Code from JournalThanks.
However, as I wrote before, I tried it with the sample code from jmp help. It works when ran from a script window but when executed from a journal script button, it seems not to generate the Python code (as a string).
Here's the help sample code:
Names Default To Here( 1 );
fd = Formula Depot();
dt = Open( "$SAMPLE_DATA/Iris.jmp" );
md = dt << Run Script( "Nominal Logistic" );
predictor = md << Publish Probability Formulas;
// Save code to string
py_code = fd <<
Generate Python Code(
Formulas( predictor ),
No Editor
);
// shortcut using predictor reference
// py_code = predictor << Generate Python Code(No Editor);
Save Text File( "$TEMP\logist.py", py_code );
// Open code in editor window
fd << Generate Python Code( Formulas( predictor ) );
Re: JMP Pro 15 Generate Python Code from JournalWhat object are you sending the "Generate Python Code" message to, when the user clicks on the Journal button?
It should be a valid Formula Depot reference. My guess is that the message is being sent to another type of object, and being ignored.
Then the variable holding what would be the Python code is empty, which results in an error when trying to save it to a text file.
So another thing you can try is to add a 'Show(py_code)' statement to your code. Always double-check the content of your variables!
I would also suggest working on this with tech support, as you will be able to share your code, data, etc.
That will help a lot with figuring out what is going on.