Bind C++ and Python

Hi,

I’d like to share a technique for creating C++ and Python bindings. This approach allows you to develop your code both locally and cross-platform. The package includes a PYPI setup with GitHub Actions configured for Linux, Windows, and macOS, making it easy to install via pip in Rhino’s ScriptEditor.

It’s been successfully tested with several well-known C++ geometry libraries, including:

You can even create Python bindings for Fortran using this method! The best part is that data transfer can happen without any copies — from simple collections to unique pointers and classes.

Here’s a step-by-step guide to creating bindings for your own C++ library:
:link: Google Slides Guide

@eirannejad — Your ScriptEditor is awesome! It has made our work at ETH Zurich much easier. Thank you, and keep up the great work!

12 Likes

I feel privileged for being a small part of this slide :innocent:

Incredible work! Thanks for sharing!

2 Likes

@Petras_Vestartas
Thank you for sharing your work!

I wonder if it may be possible to use Rhino C++ from CPython that way?
Then we don’t have to take the detour via .NET.

Jess

2 Likes

This would be a dream!
.NET layer slows things down a lot.

Since rhino is not opensource you cannot do this.

@eirannejad
Is it technically possible to wrap any RhinoDoc method? For instance to add a single point to rhino.

We have discussed this, but are not actively working on the project.

There are already a large number of nanobind based bindings written right here:

This source currently compiles with an embedded copy of opennurbs and would need to be adjusted to a different project name and link against the Rhino C++ SDK instead. Then the effort would be to add whatever Rhino specific class bindings would be needed to make the library usable.

1 Like

link against the Rhino C++ SDK instead

Do you think anyone from mcneel, in the near future, could make this working in terms of rhino integration?

I am wondering how this kind of integration works when:
a) you have open source opennurbs library
b) you have a closed source rhino software

Open or closed source doesn’t matter. We have a C++ SDK for Rhino that DLLs can use.

We can try to get this project structured for in-rhino use, but we’re all super busy right now with many other projects so it’s hard to make any promises.

1 Like

For me it would be fine if it would be limited to the ScriptEditor with the SDK installed and an activated Rhino license. No compilation needed → open source only :wink:

1 Like

Here is a start for such a project

2 Likes

Thank you very much for making it available !

Does this step exists for mac too?

Mac is still something we are trying to figure out. We are making a C++ SDK available for Mac in Rhino 9, but definitely don’t have all of the issues worked out yet.

1 Like