1
$\begingroup$

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?

$\endgroup$

1 Answer 1

1
$\begingroup$

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}]
$\endgroup$
2
  • $\begingroup$ Actually, If I need static picture, I just need to use << JavaGraphics` . But I want to plot Interaction picture. $\endgroup$ Jun 13, 2020 at 3:05
  • 1
    $\begingroup$ 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? $\endgroup$ Jun 16, 2020 at 14:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.