VB - load and SHOW an empty notebook programmatically from Visual Basic

Viewed 24

I am building an application in VB that wants to open a new second window running an empty (not existing) notebook of Mathematica, fill it with Input, show it as a different window on top of the existing VB application and evaluate a Manipulate input. I wish to do this because, for what I know, using NETLink does not allow to show dynamic graphics in VB directly.

I created a link and run Mathematica formula showing correctly the result graphics in VB using this code:

Dim ae As String = "GraphicsGrid[Partition[{SphericalPlot3D[1 + Sin[5 \[CurlyPhi]]/10, {\[Theta], 0, \[Pi]}, {\[CurlyPhi], 0,2 \[Pi]}],SphericalPlot3D[1 + Sin[5 \[CurlyPhi]]/10, {\[Theta], 0, \[Pi]}, {\[CurlyPhi], 0,2 \[Pi]}, RegionFunction -> (Sin[5 (#3 + #5)] > 0 &),Mesh -> None, BoundaryStyle -> Black],SphericalPlot3D[1 + Sin[5 \[CurlyPhi]]/10, {\[Theta], 0, \[Pi]}, {\[CurlyPhi], 0,2 \[Pi]}, RegionFunction -> (Sin[5 (#3 + #6)] > 0 &),Mesh -> None, BoundaryStyle -> Black],SphericalPlot3D[1 + Sin[5 \[CurlyPhi]]/10, {\[Theta], 0, \[Pi]}, {\[CurlyPhi], 0,2 \[Pi]}, RegionFunction -> (Sin[5 (#1 + #4)] > 0 &),Mesh -> None, BoundaryStyle -> Black]}, 2], ImageSize -> 400, Frame -> All]"

Dim MathKernel1 As New Wolfram.NETLink.MathKernel
With MathKernel1
 .AutoCloseLink = True
 .CaptureGraphics = True
 .GraphicsHeight = PictureBox1.Height
 .GraphicsWidth = PictureBox1.Width
 .Compute(ae)
End With

TextBox1.Text = MathKernel1.Graphics.Length.ToString
PictureBox1.Image = MathKernel1.Graphics(0)

MathKernel1.Dispose()

What I want to do in VB is exactly what it is shown in https://mathematica.stackexchange.com/questions/96011/launch-front-end-from-net-mathkernel-and-return-result-to-net/96493#96493 that I tried to reproduce ... but I have not been able.

In Mathematica, I have been able to open an second window and evaluate cells, as I want to do from within VB, through:

aa = CreateDocument[{Cell["Section heading", "Section"], 
    Cell["Some text.", "Text"], 
    ExpressionCell[Plot[Sin[x], {x, 0, 2 \[Pi]}], "Input"]}, 
   WindowSize -> {400, 200}];
CreateWindow[aa]

... but I have not been able to replicate it within VB.

Thanks

0 Answers
Related