1

I have following code, which can run in notebook.

CreateDialog[
 ExpressionCell[
  Plot3D[Sin[x + y^2], {x, -3, 3}, {y, -2, 2}, 
   SphericalRegion -> True], Selectable -> True, Deployed -> False]]

It will pop out a window.

I tried to run it in .wls file, but it said that

FrontEndObject::notavail: A front end is not available; certain operations require a front end.

So I add UsingFrontEnd , but still get nothing.

UsingFrontEnd[
CreateDialog[
 ExpressionCell[
  Plot3D[Sin[x + y^2], {x, -3, 3}, {y, -2, 2}, 
   SphericalRegion -> True], Selectable -> True, Deployed -> False]]
]

How to solve this problem?

Glorfindel
  • 547
  • 1
  • 8
  • 14
AsukaMinato
  • 9,758
  • 1
  • 14
  • 40

1 Answers1

1

Well, CreateDialog just cannot work. However, e.g. on Linux it is easy to let the image being popped up by the wls script, supposed that ImageMagick is installed and you can use the display function: This is the script test.wls

#!/usr/bin/env wolframscript
Echo @ ("starting " <> $Version <> "  in " <> Directory[]);
(* generating the plot *)
plot = Plot3D[Sin[x + y^2], {x, -3, 3}, {y, -2, 2}, SphericalRegion -> True];
(* exporting it to, e.g.  JPG, just works: *)
file = Export["sinPlot.jpg", plot];
(* this displays the file name *)
Echo @ file;

(* one possibility to open the file from within this script  *)
Run["/usr/bin/display " <> file];

On Windows, with ImageMagick installed as usual:

#!/usr/bin/env wolframscript
plot = Plot3D[Sin[x+y^2],{x,-3,3},{y,-2,2},SphericalRegion->True];
file = Export["sinPlot.jpg",plot]
fName = FileNameJoin[{Directory[],file}]
RunProcess[{"cmd","/c","\"C:\\Program Files\\ImageMagick\\imdisplay.exe\"",fName}]
Rolf Mertig
  • 17,172
  • 1
  • 45
  • 76
  • Actually, If I need static picture, I just need to use `<< JavaGraphics`` . But I want to plot Interaction picture. – AsukaMinato Jun 13 '20 at 03:05
  • 1
    If you want to interact from the script: not possible. The only thing you could try to do is to start a full new separate Mathematica process, somehow from within your script. Why don't you just use the notebook if you need a front end? – Rolf Mertig Jun 16 '20 at 14:29