Blender 2.8+ .Net/C# runtime api support?

So I’m not a fan of scripting languages like python at all, so that’s the main reason for wondering about this, and the future of Blender having support in using a managed language like C#. Just with the direction .Net is going with it being supported on all OS platforms now I’m wonder if something like https://github.com/dotnet/corert runtime compilation along with Blender supporting a C# api would ever likely happen?

How feasible would it be in implementing I have no idea, but still interested to see if others would like to see it happen.

Answered in one of the developer faqs.

Support for Other Scripting Languages

Supporting multiple languages is not something we’re currently interested in.

Embedding a language runtime has a significant maintenance overhead, so there would need to be very compelling reasons (besides developer preference) to add support for other languages or to move away from Python.

Oh well… Blender 3.0 right :smiley:

You can use pythonnet, it’s good opensource project that allows to call any .NET function from python, and also, allows to some extend bidirectional communication with .NET. We use it in both 3ds Max and Houdni tools. But I think python is much more versatile then .NET for scripting, and I use C# everyday with Unity, and know and use it since it appear in 2000/2001.

By the way, I’m moving away from 3ds Max (15+ years) to Blender (2.8) and I’m loving it. Very versatile, very powerful, and incredible fast for the tasks I need to do.

2 Likes

I had asked something similar a while back: On licensing and 3rd party plugins

Hell yeah i’d like c# instead of python. I understand why python was chosen initially, it being open source and all back in the 2000’s, when c# was very much not. But in the current day, yeah, c# is a sorely missed feature, python sucks nutz.

I would enjoy using C# way more in Blender than Python. I simply don’t like so many aspects of it. I passionately dislike it :slight_smile: .
However, there is quite an Blender ecosystem built around Python, so a switch won’t happen and would not make sense. Having an additional API for C# would be an unnecessary overhead in my opinion.

I expect a requirement would be to have a C/C++ API, which could then be used by C#. A C/C++ API appears way more likely to happen, even though it is an anti-feature.

as i recall devs are not agains better API and beter acces to blender data, but they just don’t have resources for that

eg.

Officially, they’re against it (this is from an older version of the wiki, but it’s still there in the 3.5 version):

Specifically for C/C++ (https://wiki.blender.org/wiki/Reference/AntiFeatures):

C/C++ Plugin API

At the moment we are not planning to accept binary plugins in Blender (which implies a C/C++ API).

Note: the pros and cons for this are quite involved and not covered in detail here yet.

1 Like

I’ve just found out about Mojo lang, a superset of Python designed for AI programming, with the choice to code with static or dynamic types, and have immutables/constants. And to top it off…has an allegedly theoretical 25K times faster execution time. It’s yet to be released to the public, private beta is currently underway. The future for python and blender programming is looking bright indeed.

I don’t see how Mojo could be useful for the future of Python and Blender. Mojo is not Python and as far as I can see, if you want the full speed of Mojo, it isn’t Python compatible anymore (that’s why I am confused by the statement it is a subset of Python). From a practical point of view, I don’t see how this would be useful for Blender.

2 Likes

a super-set, not a sub-set.
A semantically not to be overstated difference, albeit orthographically a small difference (quick to read it wrong).

greetings, Kologe

1 Like

Thanks, that’s where my confusion came from. I most likely misunderstood it in an interview. Superset makes more sense, indeed.
Though, it doesn’t change much regarding the future of Python in Blender from my current point of view.

Am I wrong in thinking that a team capable of creating a C plugin should be able to just fork Blender and write C code within the source code itself to do what they need to do?

1 Like

Not at all, it’s entirely doable. I wouldn’t be surprised if someone’s already done it

For many things, they could probably even missuse the api which Cycles uses to interface with Blender.
If memory serves me right, @KWD mentioned somewhere in some casual side discussion a while ago, he does this with respect to some personal, private fork which uses said api to have Blender interface with some custom node system (which Kevin wrote himself for fun or research purposes or whatever it be).

greetings, Kologe

Since there are no chances of C# getting into Blender (for now) I guess that we have to find other workarounds:

  • Use Blender Python only as glue code
  • Write all of the logic (heavy lifting) into another language.

Since .NET 6 and .NET 7 things started getting into the right track, and now is feasible to interoperate code among Python and .NET without any problems.

https://github.com/pythonnet/pythonnet

First you install the package:

>>> import pip
>>> pip.main(['install', 'pythonnet']

And then you can use existing C# libraries.

import bpy

import clr

clr.AddReference("System.Windows.Forms")
import System.Windows.Forms as WinForms
from System.Drawing import Size, Point

class HelloApp(WinForms.Form):
    def __init__(self):
        super().__init__()
        self.Text = "Hello World Python Blender"
        self.ClientSize = Size(400, 400)

        # create button
        self.button = WinForms.Button()
        self.button.Location = Point(0, 0)
        self.button.Size = Size(400, 20)
        self.button.TabIndex = 2
        self.button.Text = "Print Objects"
        self.button.Click += self.button_Click

        # add control to the form
        self.Controls.Add(self.button)

    def button_Click(self, sender, args):
        
        message = 'object in scene: ' + str(len(bpy.context.scene.objects)) + '\n'
        for o in bpy.context.scene.objects:
            message += '  ' + o.name + '\n'

        WinForms.MessageBox.Show(message)

    def run(self):
        WinForms.Application.Run(self)

def main():
    form = HelloApp()
    app = WinForms.Application
    app.Run(form)

if __name__ == '__main__':
    main()

Whoever is interested to try some experiments with this approach can let us know if is of any interest.

there always have been such projects though. jaques lucke used cython for animation nodes.

and python creator guido van rossum (currently employed by microsoft) works on making official python 5 times faster.

1 Like

For me personally, the intention would be to write C# code, instead of Python. Your example shows how to use C# libraries from Python. In theory, https://github.com/pythonnet/pythonnet would also allow to execute Python code from within .NET, though it would need to be thoroughly tested whether it can be used with Blender too.
Personally, I always decide against those sorts of approaches, because if something doesn’t work, there is essentially no support. Even worse, it might work with one version and then fail in future updates. That happend to me for other projects and that’s why I stick to the official stuff only and leave my personal preferences out of the way.

3 Likes