Tutorial for OpenNest

Hi,

I will try to post new tutorials for OpenNest here.

This is the first one:

Also, I am rewriting OpenNest in C# to avoid cross-platform with C++ Boost to be compatible with Mac.
I do not know how much faster or slower it will be, but at least I have NFP working correctly:

10 Likes

Thanks for trying to make this available for macOS users. Couldn’t you just compile Boost for macOS, instead of migrating everything to C#?

The main problem seems to stem from some DLLs not being compatible. The macOS equivalent of Windows DLLs, are DYLIBs, although some DLLs also seem to work on macOS. Kangaroo and other addons have these as dependencies even in Rhino for Mac?

Anyways, here’s the error I get with the main OpenNest component in Rhino 6:

  1. System.DllNotFoundException: minkowski.dll assembly: type: member:(null)
    at (wrapper managed-to-native) OpenNestMinkowskiWrapper.MinkowskiWrapper.setData(int,double,int,int,double,int,double)
    at DeepNestLib.Background.Process2 (DeepNestLib.NFP A, DeepNestLib.NFP B, System.Int32 type) [0x0022b] in <2d2793fc21e847a0b99f4f2478fd169f>:0
    at DeepNestLib.Background.getOuterNfp (DeepNestLib.NFP A, DeepNestLib.NFP B, System.Int32 type, System.Boolean inside) [0x00080] in <2d2793fc21e847a0b99f4f2478fd169f>:0
    at DeepNestLib.Background.getInnerNfp (DeepNestLib.NFP A, DeepNestLib.NFP B, System.Int32 type, DeepNestLib.SvgNestConfig config) [0x00085] in <2d2793fc21e847a0b99f4f2478fd169f>:0
    at DeepNestLib.Background.placeParts (DeepNestLib.NFP sheets, DeepNestLib.NFP parts, DeepNestLib.SvgNestConfig config, System.Int32 nestindex) [0x0015d] in <2d2793fc21e847a0b99f4f2478fd169f>:0
    at DeepNestLib.Background.sync () [0x0004e] in <2d2793fc21e847a0b99f4f2478fd169f>:0
    at DeepNestLib.Background.thenDeepNest (DeepNestLib.NfpPair processed, System.Collections.Generic.List`1[T] parts) [0x000a8] in <2d2793fc21e847a0b99f4f2478fd169f>:0
    at DeepNestLib.Background.BackgroundStart (DeepNestLib.DataInfo data) [0x002ff] in <2d2793fc21e847a0b99f4f2478fd169f>:0
    at DeepNestLib.SvgNest.launchWorkers (DeepNestLib.NestItem parts) [0x003d8] in <2d2793fc21e847a0b99f4f2478fd169f>:0
    at DeepNestLib.NestingContext.NestIterate () [0x00546] in <2d2793fc21e847a0b99f4f2478fd169f>:0
    at OpenNest.OpenNestFullComponentCleanUp.SolveInstance (Grasshopper.Kernel.IGH_DataAccess DA) [0x004c1] in <33db92caa85744f08500402479f9b22c>:0

The mac version is not released yet, but I have a prototype on my pc, that is why you get this error.
Also, here I will add tutorials for the current version since I get questions what each parameter mean.

The idea to rewrite it by c#, comes from the fact that current version uses some c++ code from Boost that is called in c# via pinvoke. There is no such thing for mac as PInvoke.

Kangaroo and other addons is pure c# that is why it works on boths systems. So dll in c++ and dll in c# is not the same thing. I know that Rhino has such knowledge but I do not have idea how RhinoCommon methods are called in .NET when many methods are in native C++.

Since I do not have mac, it was hard for me to understand how to compile the library to call c++ in c#, therefore c# version was the way to go. I also tried to ask several people about this without getting answers or solutions.

1 Like

Sure, I know. I just wanted to show you the error I get with the current version.

That’s great! Do you want me to remove my two replies, this one and the one above I mean?

Are you sure about that? I’m by no means an expert, but it seems that P/Invoke could at least work with DYLIBs on macOS (cf. source), meaning that you would probably have to compile minkowski and other dependencies with g++ on macOS to get a DYLIB, instead of a DLL.

I see! That’s something I’m interested in, too. Seems like a book with seven seals. :wink:

Yes, first of all you need a mac running macOS, or emulate macOS in for instance a VirtualBox on Windows.
In macOS Terminal (/Applications/Utilities/Terminal), you can then use g++ to compile the DYLIB, at least that’s the simplest way I know, without having to involving an IDE.

Here’s the bash command you could use:
cd Desktop/foo/
g++ --verbose -dynamiclib -o foo.dylib foo.cpp

You’ll need to keep the header file (i.e. foo.hpp) with the new foo.dylib dynamic library, since it contains the prototypes that are declared in the foo.dylib, at least until the final compilation (which will probably never happen, since C# is only interpreted?).

1 Like

3 Likes

Now it works for sheets as well as the C# version without any dependencies.

Regarding, compilation of old OpenNest @diff-arch
Yup, I need Virtual Machine for this and thanks for this:
cd Desktop/foo/
g++ --verbose -dynamiclib -o foo.dylib foo.cpp

I ll give it a try.

And I see that this might help

So in the end I am doing both ways:
a) Still using Boost and via PInvoke
b) C# version without dependencies.
Will see how this exploration will work and whether I can tackle both. C++ is always much more trickier to handle.

1 Like