I have a set of libraries in Python (Maya Python API), that I would like to have some wrappers over in C#. Currently have an ability to invoke the python code by constructing strings and sending them over to the python engine, but would prefer to have intellisense/proper python function signatures in C#. Does such a tool exist? Or is there a better way to integrate the python into the C# workflow?
-
1"Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it." – johnnyRose Dec 09 '15 at 16:23
-
The problem is described as "Invoking Maya Python API code from C# plugin leads to error-prone code", but that's what I've been doing so far. – Joe Dec 09 '15 at 16:27
-
The question relates to language interoperability, if there is a tool that helps with that, what is a better forum (SE or not) to inquire about it? I tried googling obviously. – Joe Dec 09 '15 at 16:29
-
I don't have any experience with it, but there is always http://softwarerecs.stackexchange.com/ – johnnyRose Dec 09 '15 at 16:56
-
future voters: I edited OP's title and description -- this looked like a software rec but it's really a legit strategy question – theodox Dec 09 '15 at 18:04
1 Answers
The dotnet API is really designed around the same model as the C++ api: you'd write code to manipulate the running Maya and then provide a thin wrapper in the form of Mel commands that the user can invoke directly or with tools and menus. Unfortunately that means invoking scripts from inside the plugin is going require a round trip through the script layer, with the attendant conversion costs. Plus you will then have to write C# to parse command results in python or mel and decide how to react, which will be a nightmare even if it works.
It's probably better to design the C# code as a smaller. self-contained piece which expects to be controlled from scripts (which could be either mel or Python -- you get that for 'free' when your plugin exposes commnads).
Python Tools for Visual Studio does give some degree of autocomplete for Python code inside visual studio but I don't think it will work in a .CS file. If you really need to provide significant amounts of script (as opposed to sticking to the minimalist design, which I still think is superior) you can maintain a separate PTVS project to create the python infrastructure as a sub-project and then package the files it creates as resources in your C# plugin. However apart from things you can't avoid -- like (boo! hiss!) AETemplates -- the sane strategy is to treat the plugin as a provider of high-performance functions to be called from script rather than the other way around.

- 12,028
- 3
- 23
- 36
-
Fair enough, in some case with Maya one needs to call C# from python, and in some cases - python from C#. The question relates to the situation where one's writing a plug-in in C#, and the python API provided by Maya is simpler to use than the C++/C# one. Having the python functions more readily available in Visual Studio is what I am looking for here. I was _also_ looking for a more general solution along the lines of "is there SWIG for python", but that somehow makes it off limits for SO (thanks for trying to resurrect my question though). – Joe Dec 10 '15 at 15:59
-
In a given python scope you can get all the names using reflection, and get the names within those names, etc. ad infinitum -- that's how IDE's like PVTS or PyCharm do it. However it's a lot of work to do right. You can do a cheapo version using the `inspect` module but its probably not enough help to solve your problem – theodox Dec 10 '15 at 21:05