The anybodymagic extension for IPython will run AnyBody macro commands directly from the IPython Notebook. This is a very easy way to work with the AnyBody console application.
The AnyBody Modeling System must be installed on the computer for this extension to work.
The extension is installed directly from github with the %install_ext
command.
%install_ext https://raw.github.com/melund/anybodymagic/master/anybodymagic.py
Installed anybodymagic.py. To use it, type: %load_ext anybodymagic
When the extension is installed, it can be loaded with the %load_ext
command.
%load_ext anybodymagic
Anybody macro commands are executed with the %%anybody
cell magic. The remaining cell is passed directly to AnyBody as macro commands
Here is an example
%%anybody
load "Knee.any"
operation Main.MyStudy.InverseDynamics
run
exit
The cell magic has a few options, which are given on the same line eg. %%anybody --out consoleoutput
--dir c:/workdir
Changes the current directory
--out consoleoutput
Stores the console output to consoleoutput
** --bg
**
Run the macro commands in a background process. In this case the -out
command will give a PIPE to console output.
** --dump
**
Exports variables to the Notebook name space
%%anybody --dir C:/Users/Morten/Desktop --dump
load "Knee.any"
operation Main.MyStudy.InverseDynamics
run
classoperation Main.MyStudy.Output.Abscissa.t "Dump"
classoperation Main.MyStudy.Output.MaxMuscleActivity "Dump"
exit
Dumped variables: - Main_MyStudy_Output_Abscissa_t - Main_MyStudy_Output_MaxMuscleActivity
The dump'ed variables are now avaiable directly in the Notebook. So let us plot them:
plot(Main_MyStudy_Output_Abscissa_t, Main_MyStudy_Output_MaxMuscleActivity)
xlabel('time')
ylabel('Max muscle activity')
<matplotlib.text.Text at 0x7698d68>
The -bg command will excute the cell in a background process.
%%anybody --bg --out outpipe
load "Knee.any"
operation Main.MyStudy.InverseDynamics
run
classoperation Main.MyStudy.Output.Abscissa.t "Dump"
classoperation Main.MyStudy.Output.MaxMuscleActivity "Dump"
run
exit
Starting job # 2 in a separate thread.
lines = outpipe.readlines()
print "".join(lines[-10:])
Total simulation time: 0.018 *************************************************************************************** #### Macro command > exit Closing model... Saving modified values... Deleting last loaded model... ...Model deleted.