# Tag Info

26

Copying my answer from StackOverflow (edit, now updated) ... If you are on Windows (with .NET), then you could use Mathematica's NETLink functionality in conjunction with the WebBrowser class to capture a screenshot of a web page: Needs["NETLink"] LoadNETType["System.Drawing.Imaging.ImageFormat", AllowShortContext -> False] ...

24

UPDATE The following steps are no longer necessary if one is using Mathematica version 9 -- it comes preconfigured to use .NET 4.0. NETLink uses an interlude .NET application to broker communication with the framework. The application is called InstallableNET.exe (InstallableNET32.exe on 32-bit systems) and can be found in this directory: SystemOpen @ ...

22

IronPython requires .NET 4.0 to run. As of V8, Mathematica launches .NET 2.x by default. See this question for details about how to use .NET 4.0. Having done that, we need to load the IronPython assembly into the .NET framework: Needs["NETLink"] InstallNET[]; $pythonDll = "C:\\Program Files (x86)\\IronPython 2.7.1\\IronPython.dll"; ... 21 The solution is forcing .NET/Link to load its 32-bit executable instead of the 64-bit one. Since Mathematica communicated with the .NET/Link process through MathLink, it does not matter if the Mathematica kernel is 64 bit and the .NET/Link executable is a 32 bit version. They are separate processes. However, the .NET/Link executable must match the DLL ... 18 You don't need the initial InstallNET[]. That should come after Needs["NETLink"]. I made a post on this topic a while back, here: http://forums.wolfram.com/mathgroup/archive/2011/Oct/msg00386.html Some code to illustrate the method: Needs["NETLink"] ReadFromExcel[file_String, cell_String, rows_Integer, cols_Integer] := Module[{excel, workbook, ... 15 To access the errors, you need to invoke the Front End directly from the kernel. In effect, you end up telling the kernel to tell the FE to tell the kernel to do something, so that the FE can report any errors it finds. The method I use is SetAttributes[getFrontEndErrors, HoldAll]; getFrontEndErrors[gexpr_] := Module[{nb}, ... 15 Being the fan of Mathematica<->CLR interop that I am, your question has inspired me to try to get IronPython fully working with Mathematica for the last couple of days. I haven't yet had total luck. Part of my problem is that I don't have a Windows Mathematica license, so I can't fully double-check my work. While I'm trying to hunt down Mathematica for ... 14 Excel VBA enumeration values cannot be accessed symbolically through COM. We must use the corresponding numeric values found by consulting the Microsoft Excel object model enumeration reference. The relevant enumerations in this case are XlBordersIndex (xlDiagonalDown = 5) and XlBorderWeight (xlThick = 4). Once we know the enumeration values, the code is ... 13 Even the path is corrected, it still cannot run, since the argument type should {"double*", "double*"}. Here is my memo on calling dll created by gortran using NETLink: Advantages of NETLink as compared to Mathlink: FORTRAN functions and subroutines can be called using .NET/Link without writing additional C wrapper which is necessary in Mathlink. ... 12 Yes, it is, but it's cumbersome (at least as of Mathematica 8). The hardest part is that you have to manually do a lot of the juggling required to work with .NET generics and extension methods. For example, let's translate a straightforward solution to Project Euler's Problem #1 ("Add all the natural numbers below one thousand that are multiples of 3 or ... 12 AFAIK there is no equivalent to the Matlab builder (yet?). There are some similar functionalities but, as far as I understand and know, there is nothing that would perfectly match what you seem to need. For deploying functionality written in Mathematica for use from a C# program I see these three possibilities: Deploy as Mathematica-Application (with GUI) ... 11 To use .NET/Link from a Mono program, you need to make sure that the system can find the MathLink shared library. This generally means adding the appropriate path to an environment variable that the system uses for library lookups. You can do this is in the standard way that is appropriate for your OS/shell program, either in a shell config file or on the ... 10 Or simply use ReinstallNET["Force32Bit" -> True] which is a convenience function that calls UninstallNET[] InstallNET["Force32Bit" -> True] 8 Here is an idea - it's by no means perfect, but then again, the comments indicate that there won't be a perfect solution: In your .NET application, create a web view (I don't know the details for this, but that would go beyond the scope of this forum anyway - I've done similar things in Cocoa on Mac, so you should be able to find analogous libraries for ... 7 Per request, I'm posting this as an answer: The same problem is mentioned in the following support article: http://support.microsoft.com/kb/320369 The problem appears if the language of Excel differs from the locale setting of the operating system. One workaround is to set the system locale to match with the language of Excel (probably US English for ... 7 The command line option to call the kernel with to suppress the taskbar button is -noicon. You need to pass this flag to MathKernel.exe when launching it. Here's a demonstration from within Mathematica: kernel = LinkLaunch[First[$CommandLine] <> " -mathlink -noicon"] This will launch a new kernel and connect to it. On Windows, the new kernel will ...

7

This is apparently a 32-bit COM object, so you need to force .NET/Link to run in 32-bit mode: Needs["NETLink"]; ReinstallNET["Force32Bit" -> True]; p = CreateCOMObject["PinPoint.Plate"] Generally, the only time you need to worry about bit-ness issues is when you are calling non-.NET code, such as a 32-bit DLL via DefineDLLFunction or, as here, a ...

7

First off, I should mention that Vensim also has a Java interface that you could call using J/Link. The Java signature of this particular function is static String[] get_info(int infowanted); so you can see that the different strings are conveniently returned in an array for you. But you can also do what you want using .NET/Link's DefineDLLFunction. You ...

6

The problem here is that the Gridlines specification error message is not a kernel error message (you'll note that it is not printed with the standard Func::tag format). Instead, this warning text is generated by the front end during the rendering of the graphic. The actual generation of the gridlines values is deferred to the moment when the graphics ...

6

The "messages" handled by the MessageArrived event are MathLink messages (like interrupt requests), not Mathematica warning messages. Mathematica messages are delivered as part of the stream of packets. To get them in your program, use the PacketArrived event. Here is an example. Note that messages come as a MessagePacket followed by a TextPacket, and for ...

5

If you'll accept solutions involving other technologies, then how about using sed? On a unix system, to read in file1, delete row n and output to file2, you'd do: sed -e 'nd' file1 > file2 The quotes in 'nd' are not necessary in this case, since there is only one instruction. However, if you're doing more complicated stuff with regular expressions, you ...

5

Here is a way to invoke System.DateTime.FromOADate using NETLink: Needs["NETLink"] InstallNET[]; LoadNETType["System.DateTime"]; fromOADate[d_] := DateList @ NETBlock @ SystemDateTime`FromOADate[d]@ToString[] Note, however, that FromOADate does not share Excel's backward-compatible implementation of Lotus 1-2-3's date bug. To see this, we introduce ...

5

I've got VBA calling Mathematica functions. It's not without issues, but maybe some other smart people here can help with the hiccups. First things first: The .dll that Mathematica includes with its installation for .NETLink is not COM-compatible, meaning that VBA cannot find entry points into the dll functions. To get around this, .NET must be installed ...

5

To transfer an EMF graphic you can use this: kernel.Compute("ExportString[Graphics[Rectangle[]],{\"Base64\",\"EMF\"}]"); byte[] decodedBytes = Convert.FromBase64String(kernel.Result.ToString()); File.WriteAllBytes("C:\\Temp\\output.emf", decodedBytes); Ref: http://stackoverflow.com/questions/7755810/converting-graphics-with-exportstring also: ...

5

Such a library is not meant for dynamic loading and typically will not contain all of the information necessary to properly link it at runtime. It also may not contain relocatable code. If you want something that is loadable at runtime, the most straightforward approach is probably to write the code for a corresponding dynamic library (.dll file) and link ...

5

I have been thinking about this for quite some time but didn't had enough spare time to develop it into something finished. Nevertheless, I want to give my two cents. As you have already understood, there are two different problems here. First, you want to secure your package from looking directly into the .m file. Second, you need to secure your package ...

4

I'm presuming that you already have a command which generates a graphics and you're trying to retrieve it through the MathKernel. If so, try the following: 1. Set the CaptureGraphics Property on your MathKernel to true. 2. Run MathKernel.Compute(command) 3. If your command successfully returned a graphics (you could check by Mathematica notebook), ...

4

I am answering my own question to help out other .Net/Mathematica developers in the future. I am using random file names (DTWERG, ERYFGJ, IYIGGD) and it turns out when Mathematica exports an image file that has a slash and followed by : b, t, n, f, r it recognises/honors the escape slash. For example when a file name starts with an r as per the ...

4

The solution which worked for us may not be practical for you, but we faced a similar scenario. However, we also knew that across all our users, the actual times that a call to MMA would be needed would be few and far between. The answer for us is a small pool of floating licenses for MMA. That said, Wolfram were very helpful, and for a large scale ...

4

First, I like to apologize for answering my own question because I overlooked some essential initial steps when working with MonObjC. Preconditions In order to access the Cocoa-APIs from Mathematica via .NETLink there need to be installed 2 separate packages: The Mono environment which can be obtained from here: Mono Project Download Page The MonObjC ...

Only top voted, non community-wiki answers of a minimum length are eligible