Blender - commands in C# 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.

Related

Running several python scripts from C#

I am hoping that someone might be able to help me out here. I am relatively new to C# and am trying to execute some Python code I wrote from within a C# winform app.
What I would like to do is input a name from a text box within the winform and have it process through the python scripts and return a result in another textbox on the winform.
I have found several good examples of how to execute a single script within C#, but I am having some trouble understanding how I can reference multiple scripts.
As an example, I have one python script that references two other scripts within code
from FindTelephone import *
from FindAddress import *
def createPerson(name)
telephone = FindTelephone(name)
address = FindAddress(name)
....
Is there a way to have C# point to a reference of my other python scripts before running my main script?
Thanks in advance for the help.
Marshall
Like in these posts?:
Call Python function from c# (.NET),
run a python script from c#?
Or
You might want to look into pythonnet.
Or
If you want an easyer way of doing this then I recommend using Iron Python in place of normal Python. IronPython is an open-source implementation of the Python programming language which is tightly integrated with the .NET Framework. Means that it is much easyer to use with C# and Windows Forms and looks almost just like normal Python.
Or
For in case you are using Visual Studio, VS has some Python tools that might help you in your quest. Link. You can find more documentation Here This last link is provided by Jedediah from comments so vote his comment up if you liked this last link.
Other handy link: Integrating Python With Other Languages

Using Visualization Toolkit with IronPython

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.

C# injecting C++ DLL

I am trying to inject a C++ detour dll using a C# application using Syringe.
Here is what I have so far:
-A dll to inject which hook both recv/send from wsock32.dll and log the communication (http://pastebin.com/JvnmYuz0)
-A C++ loader which start the target application then load the dll to it ( pastebin . com/mX68nTnx) //Sorry, I cant post more than 2 links
-A C# app that inject the dll in any process (http://pastebin.com/FLRj45YF)
But I am having some problems:
1- I do not want to use the c++ loader to start the application then inject the dll, I use it only to test the dll hooking, and it is working well, it does hook and log to file the communication
2- I want to inject the c++ dll (in any process I want) using a c# application (using Syringe). I can inject it with no problems, but it does not hook the recv/send functions as it does when started with the c++ loader, however, it says that everything was attached successfully, but it does not log anything to the file, not even call MyRecv/MySend. I once received error 8 (ERROR_NOT_ENOUGH_MEMORY) from DetourTransactionCommit() while detouring send/recv functions, but now it says there is no error
3- After being able to handle the communication using MySend/MyRecv, I want to send the communication back to the C# application then do the work there.
I am very new at c++ and dll injecting but I have some experience with c#.
It does not need to necessary use the syringe method to inject.
I have tried to use EasyHook without success.
Any injecting method will be great, as long as I can inject the dll to any process then work the communication on a C# application. I do not want to do the work on the C++ dll because I am very new to C++ and it seems to be very very hard to do simple things, the learning curve is not very friendly
thanks
PS: I do not want to hack anything/anyone, I just want to create a Ultima Online tool

How to create a .lib file from a C# DLL?

I need to create a .lib file from a C# DLL (I think it is C# becuase of this code which calls to the dll https://code.google.com/p/thunder-missile-api/downloads/detail?name=MissileLauncher.cs&can=2&q=) In other word's I need to create a .lib for DreamCheeky Thunder Missile Launcher DLL, which comes with their software .
Now, what I need to do? I need to operate this device using C++. Easiest way is using their own DLL. The above linked code does it in C#.
I tried importing the DLL file into the project C++, but it seems like some methods are missing, specially methods like moveMissileLauncher() which are called in the C# code.
And the best thing is, I might want to move to QT (most probably) so you know, having a .lib is a good idea.
Crating a lib from a managed dll will do no good. You need to use interop
http://msdn.microsoft.com/en-us/library/ms973872.aspx
In your specific case, I would write a C++ lib that exposes the methods you need/want to call and forwards them to the managed C# dll using interop
I would do that in C++/CLI, personally.
A good, more recent article on the options you have is here http://msdn.microsoft.com/en-us/magazine/dd315414.aspx, or look here on SO for COM/.NET interop and you will find plenty of answers.
You want to call managed C# code from your c++ application. Here is tutorial to make someway to call c# code from your c++ application, i have used this method before, and works fine for me.

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

Categories

Resources