# Tag Info

35

Get all the files here. .NET Mathematica Word Library You will need to use a Microsoft library to open word documents. In a language such as .Net it is very easy; just open Visual Studio, reference the Microsoft.Office.Interop.Word .NET DLL (for Words) and the C:\Program Files\Open XML SDK\V2.5\lib\DocumentFormat.OpenXml.dll (for Formulas in the MathML ...

32

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] LoadNETType["System.Windows....

19

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 ...

8

Updated Response The internal name of System.Collections.Generic.List is "mangled". We can see what that internal name is by using NETTypeInfo: NETTypeInfo[LoadNETAssembly["mscorlib.dll"], "Classes", "*Generic.List*"] We can see that the internal name is System.Collections.Generic.List1[T]. We can create objects of this type directly with NETNew ...

8

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 ...

8

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 ...

8

Yes it is possible to write such a code and I will present the code and sample usage below. The motivation for this question/answer is this Java reloader by Leonid Shifrin and I borrowed some code from his answer. Simplistic C# Reloader The code below is a C# reloader. It takes a string of C# code and (optionally) a C# compiler path, attempts a compile and ...

8

In the Excel object model, the worksheet symbol Cells represents a property, not a method. In Visual Basic and other languages, many properties have a default method called Item. NETLink does not fully implement this notion of a default method: ws@Cells[3, 3]@Value (* 3 *) but: $i = 3; ws@Cells[$i, $i]@Value (* (NETLinkObjectsNETObject$1412516038$... 7 There is now a built-in way to do this: WebImage["http://stackoverflow.com"] session = StartWebSession["Chrome"]; WebExecute[session, "OpenPage" -> "http://stackoverflow.com"]; WebExecute[session, "CapturePage"] WebExecute[session, "SetWindowSize" -> {600, 400}] WebExecute[session, "CapturePage"] 7 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 ... 7 Here is one way to do it, using WebUnit: Needs["WebUnit"]; InstallWebUnit[]; StartWebSession[]; OpenWebPage["http://suggestions.livejournal.com/825341.html"]; Then, use JavascriptExecute to get all the links in the document and select only the ones that have the text EXPAND in them: expandLinks = Flatten @ JavascriptExecute[" var links = document.... 7 Under Windows, this can be done with NETLink by modifying code published here. Needs["NETLink"] WriteToClipboardSVG[g_] := Module[{png, strm, dataObject}, InstallNET[]; png = ExportString[g, "SVG"]; NETBlock[ strm = NETNew["System.IO.MemoryStream", ToCharacterCode[png]]; dataObject = NETNew["System.Windows.Forms.DataObject"]; dataObject@... 7 Quoting from the Underscores in .NET Names subsection within the Calling .NET from the Wolfram Language section of the NETLink Tutorial: .NET/Link maps underscores in type, method, property, and field names to "U". So me must use: vbextUComponentTypevbextUctUStdModule The documentation does not mention it, but in the extremely unlikely event that this ... 6 Okay, I tried this and it seems to work. I copied NETLink from a Mac to /opt/Wolfram/WolframEngine/10.0/SystemFiles/Link. I installed the full mono package: sudo apt-get install mono-complete Started wolfram, loaded <<NETLink, then evaluated InstallNET[]. It seems to work. I don't know much about .NET though so I can't test in detail. 6 In v10, the Windows version no longer installs the MathLink libraries to \Windows\System32. The recommended way of dealing with this is to 'redist' a copy of ml32i4.dll with the app. 6 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 ... 6 The DLL file was Blocked. The solution was to Unblock it (right click on DLL > choose Properties > click the Unblock button). You need to restart Mathematica and load the DLL in again. 6 First, we must load the PresentationCore assembly to make the type System.Windows.Clipboard available: Needs["NETLink"] InstallNET[]; LoadNETAssembly["PresentationCore"]; Second, System.Windows.Clipboard is a static class so it cannot be instantiated using NETNew. We must import its static members instead: LoadNETType["System.Windows.Clipboard", ... 5 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 ... 5 I don't know much of .net and it probably shows, but at least I got something to work albeit very,very slowly. Your code (which I also turned into a bitmap on the clipboard using Mathematica's "Copy as Bitmap" menu item): Needs["NETLink"] InstallNET[]; LoadNETType["System.Windows.Forms.Clipboard", StaticsVisible -> True]; img = GetImage[] Using a few ... 5 Done Needs["NETLink"]; InstallNET[]; LoadNETType /@ {"System.Windows.Forms.Clipboard", "System.Drawing.Rectangle", "System.Drawing.Imaging.ImageLockMode", "System.Runtime.InteropServices.Marshal"}; img = ClipboardGetImage[]; width = img[Width]; height = img[Height]; lock = img[ LockBits[RectangleFromLTRB[0, 0, width, height], ... 5 There are some minor errors that need to be corrected: The main problem is that C# methods must be called using the syntax obj@Method[args]. The C#-looking expression obj.func1("hi there") will be interpreted as the (nonsensical) Mathematica expression Dot[obj, func1 * "hi there"]. The arguments to add must be passed as individual arguments instead of as a ... 5 We can get a list of all .NET types that can be loaded using LoadNETType like this: Needs["NETLink"] InstallNET[]; LoadedNETAssemblies[] // Map[GetAssemblyObject[#]@GetTypes[]&] // Flatten // Map[#@FullName&] // Sort // Short[#, 5]& (* { Accessibility.AnnoScope,Accessibility.CAccPropServices, Accessibility.CAccPropServicesClass,... 5 It works with code. Scan[(ws@Cells[#, #]@Value = #*100) &, Range@10] It seems that vars i in ws@Cells[i, i]@Value be not evaluated immediately when the loop goes. I wonder is it a bug in NETLink package? Update v1: (ws@Cells[#, #]@Value = #*100) & /@ (Range@10); Update v2 using Range to fill values faster content = Table[i*j,{i,1,100},{j,1,100}]... 4 There is an easy way to achieve what you want. First, let's load some sample package, encode it and re-import it as string: file = FileNames["Collatz.m", {$InstallationDirectory}, Infinity]; encoded = ToFileName[$TemporaryDirectory, "encoded"]; Encode[First[file], encoded]; encCode = Import[encoded, "Text"] (* mcmM$RqUiqylb8ORSH!A>J.... *) After that ...

4

With a lot of help from this answer: Connect Frontend to Kernel Started by JVM via JLink here is a demo that opens a notebook from .NET (via button1), allows the user to make a dynamic manipulation, and then sends the result back to .Net where it is displayed in the form. using System; using System.Windows.Forms; using Wolfram.NETLink; using System....

4

I do not know any C#, but this seems to be answered in the documentation. Since I am reading the local copy, not an online version, I cannot post links. Here are screenshots instead: Thus if you need to specify the location of the Mathematica kernel to use, pass the appropriate string to CreateKernelLink(). This is not simply the path to the kernel, but ...

4

The crux of the issue is that the symbol WorksheetClass.Pictures is a method, not a property. When using NETLink, methods must always be followed by an argument list, even when no arguments are being specified. We can distinguish between methods and properties by inspecting the NETTypeInfo: NETTypeInfo["Microsoft.Office.Interop.Excel.WorksheetClass"] ...

4

If you are referring to the Windows File Explorer, then we can use NETLink and the Shell API to get a list of open windows: Needs["NETLink"] InstallNET[]; shellWindows[] := NETBlock@Module[{app, windows, w, item} , InternalWithLocalSettings[ app = CreateCOMObject["Shell.Application"] , windows = app@Windows[] ; Table[ Internal...

3

I have just discovered that there is another way to make generic types and there is an advantage in this solution that I am going to demonstrate. I will continue the example offered by WReach, this helped me really a lot to make my first steps as a newby in Mathematica NETLink ;-) \$stringListType2=LoadNETType["System.Collections.Generic.List1[System.String]...

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