1
$\begingroup$

I use Mathematica to create a series of PNG images in a for loop. I want to execute the notebook from the command line in macOS. I exported it as a wolframscript -- see below -- but nothing happens when I execute the script using wolframscript.

#!/usr/bin/env wolframscript
(* ::Package:: *)

(* ::Input:: *)
(*fps=60;*)
(*dur=4;*)
(*tmin=0;*)
(*tmax = 8*Pi;*)
(*A=-0.125;*)
(*B=0.003;*)
(*name = surface_deformation;*)
(*For[i=0,i<=fps*dur,i++,*)
(*t=tmin+(tmax-tmin)/(fps*dur)*i;*)
(*surface=ParametricPlot3D[{-2*x*(Sin[t]*A*Exp[-(x^2+y^2)/B]-1)/(x^2+y^2+1),-2*y*(Sin[t]*A*Exp[-(x^2+y^2)/B]-1)/(x^2+y^2+1),(x^2+y^2-1)*(Sin[t]*A*Exp[-(x^2+y^2)/B]-1)/(x^2+y^2+1)},{x,-0.2,0.2},{y,-0.2,0.2},PlotRange->{{-0.5,0.5},{-0.5,0.5},{0.8,1.2}},Boxed->False,Axes->False,ImageSize->{640,480},PlotStyle->"BlueGreenYellow"];*)
(*Export["~/Movies/mathematica/"<>ToString[name]<>"/"<>ToString[name]<>"-"<>ToString[i]<>".png",Show[surface],Background->None]*)
(*]*)


(* ::Input:: *)
(**)


(* ::Input:: *)
(**)

```
$\endgroup$
4
  • $\begingroup$ Every line that begins with (* and ends with *) is a comment - that is, it is unexecuted. If you remove those characters from the lines with code (from fps to the ]), the code appears to execure just fine. $\endgroup$
    – Carl Lange
    Jan 12 at 11:46
  • $\begingroup$ @Carl Lange Duh! Many thanks! Is there a reason why Mathematica exports in this way? It would make a lot more sense to me to have a file that produces an output. $\endgroup$
    – 220284
    Jan 12 at 11:54
  • $\begingroup$ Mmm, not that I'm aware of, but I don't use that functionality. Normally I would just copy the code out of the notebook and into a plaintext file by hand. Glad to help! $\endgroup$
    – Carl Lange
    Jan 12 at 12:04
  • 1
    $\begingroup$ @220284 How are you exporting the file? Try changing all the cells you want to export to Initialization cells. $\endgroup$ Jan 12 at 14:40
2
$\begingroup$

Every line that begins with (* and ends with *) is a comment - that is, it is unexecuted. If you remove those characters from the lines with code (from fps to the ]), the code appears to execute just fine.

#!/usr/bin/env wolframscript

fps=60;
dur=4;
tmin=0;
tmax = 8*Pi;
A=-0.125;
B=0.003;
name = surface_deformation;
For[i=0,i<=fps*dur,i++,
    t=tmin+(tmax-tmin)/(fps*dur)*i;
    surface=ParametricPlot3D[{-2*x*(Sin[t]*A*Exp[-(x^2+y^2)/B]-1)/(x^2+y^2+1),-2*y*(Sin[t]*A*Exp[-(x^2+y^2)/B]-1)/(x^2+y^2+1),(x^2+y^2-1)*(Sin[t]*A*Exp[-(x^2+y^2)/B]-1)/(x^2+y^2+1)},{x,-0.2,0.2},{y,-0.2,0.2},PlotRange->{{-0.5,0.5},{-0.5,0.5},{0.8,1.2}},Boxed->False,Axes->False,ImageSize->{640,480},PlotStyle->"BlueGreenYellow"];
    Export["~/Movies/mathematica/"<>ToString[name]<>"/"<>ToString[name]<>"-"<>ToString[i]<>".png",Show[surface],Background->None]
]

When I run this using wolframscript test.wls, it executes and generates a bunch of images in the expected directory.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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