Using Visualization Toolkit with IronPython - c#

In my application, I have provision to run Python scripts through IronPython. In one of the requirement, the data from my C# application should be displayed in 3D using Visualization Toolkit. When I try to use VTK in a script and execute it, I get "ImportError: No module named vtk" error. I have searched for file named vtkCommonPython.pyd but cannot find it on my computer. Should Python be installed even after installing IronPython? What is the correct way to use VTK from IronPython?

In most cases, IronPython does not work with native/CPython modules like what vtkCommonPython.pyd seems to be. You will probably want to look at .NET bindings for VTK in order to use it from your IronPython scripts.
ActiViz.NET might be what you should be using. Wiki/Documentation, Download
Other modules containing only pure python should typically work fine. It's 'just' the native extensions that do not work as there is no easy (and built-in) way to make native code callable from .NET/IronPython using the same conventions as in CPython.
For additional info see the FAQ ('Compatibility') and the issue tracker.
You might also want to keep an eye on the recent effort to revive and port ironclad to IronPython 2.7. This project aims to provide the marshalling layer required to invoke CPython modules.

Related

Blender - commands in C# C++

I got a task to establish GMS2 -> Blender one way communication. Dll extending GMS2 needs to be written either in C# or C++. Problem with Blender is that it has no ports like Maya has. So I tought about a solution via sockets but not sure if that is the right way.
I don't request any code, just herebly asking for a pointer (pun).
Blender uses python to create addons, a python addon can be created that opens a socket and alters the internal data. One example would be the network render addon that is included with blender. You can also use the subprocess module to pipe data from an external program, see this question.
If you need to use C/C++ within the addon, you have several options. An addon for blender is a standard python module - with some required methods and properties. A python module can be a dynamic library compiled from C/C++. You can also use ctypes to access standard libraries from python code. Another option is to create a basic addon and use cython to turn it into C code which you can then add your code to, cube surfer and animation nodes are example addons that use cython to compile a shared library.

Can't load Mono.CSharp.dll in either Unity3D or a C# project

I'm working on an online video game project using Unity3D for the clients, and C# servers.
I'm trying to use some code eval for a specific feature, but I can't get it to work.
I went with Mono, because it seemed to be one of the lightest and one of the simplest. I installed Mono and got the "Mono.CSharp.dll" for .Net 4.6 from "Mono\lib\mono\4.6-api". (Both Unity and my servers are configured to use this version of .Net). I dropped it in the Unity assets, and referenced it on my servers.
But I have errors on both Unity and the servers. In Unity there is :
Loading script assembly "Assets/Scripts/Common/References/Mono.CSharp.dll" failed!
And there is an exception on the servers (my IDE is in French so I can't really copy/paste it), but it basically tells me it can't use Reference Assemblies for build, but only for reflection.
To describe the feature I want to create (because you'll maybe have a better solution), I want to be able to create spells from an external tool. Spells are made of SpellEffects. Let's say there is a SpellEffect called DealDamage, constructor takes an int (for the damage amount). I want to be able to write "DealDamage(50)" on my external tool, then take the string, and build a new DealDamage(50) from it.
I know I could find a way to interpret some code by myself, but it would be a lot more work for a far less flexible system.
It was really hard to find any help online for this problem, so as a last hope I'm turning to you.
I'm not exactly sure why you're trying to import Mono into Unity. It's already included in the installation package. If you want to make a modular spell builder, just create a regular application with your preferred language, in your preferred IDE, and save all of your spells as a JSON or XML file, and then import those into Unity. On the Unity side, just build a class to parse the files.
To get you started, take a look at the JSON.Net library. You can serialize your files into C# classes with it.

Using Mapnik in .net environment

Has anybody used Mapnik for rendering Maps from .net c# environment? I would like to use it to render maps in a desktop application developed under .net4. I found it the best open source map renderer tool, much more better, than the well known sharpmap, dotspatial (...). The 'only' problem is that it was written in C++ and Python and does not have a trivial way to use it from C#.
Do you know any .net Mapnik wrappers? Do you know any sample code?
I've just published my attempts in C# bindings.
They are available at: http://sourceforge.net/projects/mapniknet/
Some good new about Mapnik-.Net integration:
"Another thing that will help Windows developers is a way to use Mapnik from .Net languages. Although a full .Net wrapper is too much work besides all the other issues, hopefully I can make a meaningful start and open the door for .Net developers to leverage Mapnik in their applications."
Source: Mapnik homepage http://mapnik.org/news/2011/jun/09/gsoc_2011_windows_build_system_introduction/
NET-Mapnik
You might want to give this a try. Its pretty recent and has a simple example with options to create vector tiles.
https://github.com/kernelsanders/NET-Mapnik
So, finally I hacked it. Not a nice solution, but it works at least. In nutshell it operates in the following way:
developed a python script, which takes parameters as command line arguments. (using python api of mapnik)
call this python script by shell fom c# code (Process)
after map image has been generated, I show it in SharpMap as a background layer
In case of any map refresh (zoom, pan) I regenerate 'mapnik map layer'. I have also some kind of cache, in which I can store generated maps, so I can make tricks by using earlier generated map images or pre-generate them (e.g. generate maps for the next zoom level when user uses zoom tool). I also use some asynchron calls to do this, so I can create 1-3 map images paralelly.
The weak part of this solution is the communication between python and c# modules. I could not find better than command line arguments + shell.
My solution works, mapnik is fast, can genarate my maps less than a sec.
If you have any advice on .net - python communication (NO ironpython, it is not suitable for manik api), pls write it here. Thx.
Do you know about TAO Project?
It is a .Net project that takes unmanaged opengle library to .Net Managed Form by calling DllIMport() in C#.
You must do it for Mapnik, simaliar to TAOFramework.net

How to capture from webcam in Linux using Mono?

How can I capture a frame from a video-4-linux device (e.g.: /dev/video0) using Mono and C#? OS is Angstrom Linux running on BeagleBoard.
I have done v4l2 capture using C. This is probably the only language I would chose to do it in as well. There are a lot of low level calls you need to make into the driver. You need to map kernel memory into your app and copy buffers. You also have to set a ton of configuration for the device. If you need to I would consider writing a C library and using Platform Invoke. Another alternative is to write two programs and send the data over to your C# app via some sort of IPC.
You can use Emgu CV for this, it specifically advertises that it can be compiled using Mono.
Main Site: http://www.emgu.com/wiki/index.php/Main_Page
Compiling in Mono: http://www.emgu.com/wiki/index.php/Compiling_with_Monodevelop
Sample Code for Capturing Webcam Video: http://www.emgu.com/wiki/index.php/Camera_Capture_in_7_lines_of_code
I am not familiar with Mono or C# on linux, but you may have to write an interface module that exposes the diver API, or a reasonable abstraction. I think you then might be able to import the module in the C# code. It looks like Mono does support the DLLImport.
(http://www.mono-project.com/Interop_with_Native_Libraries)

How can I install a printer using .NET?

I have an .INF for a virtual printer that I need to install from a .NET Application. I have done this before using batch scripts, but I am looking for a snippet of code to do this in the .NET Framework.
There's nothing particular about the printer .INF, so any code that installs a printer from an INF in C# or VB.NET will work.
I believe this is possible via interop to native win32 APIs, but I've found its much, much easier just to use a System.Diagnostics.Process() to call into printui.dll via:
rundll32.exe printui.dll,PrintUIEntry /?
Perhaps you're already using that in the mentioned batch script, but if not the parameters are documented here: PrintUI.DLL User's Guide and Reference
Just be sure to test it against all operation systems you need to support. Some options either do not exist in all Windows releases or have been renamed (although I think they're the more esoteric options - installing an .INF will likely work across the board).
You are going to want to look at the WMI objects available. These give you a finer control of the local machine settings. Take a look at the WMI code creator from Microsoft, I believe this will generate some example code you can leverage to solve your problem.
Administering Printer Settings in C# for Flexible Printing
see this article, it uses an MS Platform SDK DLL called PRNADMIN to manage printers, printer-drivers, printer-ports, ...etc.
I personally use it in a commercial project to install a printer driver and change the printer port to local port to intercept the Postscript. and it works like a Charm.
Alternatively you can use some pre-installed vbscripts that come with windows in C:\Windows\system32\Printing_Admin_Scripts and here is a an articles for them:
http://technet.microsoft.com/en-us/library/cc771846.aspx
This is not the ideal solution, but if nobody else answers, you can create a temp batch file and invoke that through C#/VB.NET.
Someone else will probably know a more natural way to do this.
You will need to wrap the setup APIs using PINVOKE or a native COM object.

Categories

Resources