Grasshopper

algorithmic modeling for Rhino

Hello,

Let me start by saying.. good C++.. but zero C# knowledge.

I want to built a GH plugin to link an analysis library that I have with GH.

I have 2 options currently available (thinking with a C++ head).

1) add my code to the VStudio project and link/compile it with the C# code, which I think its not possible/easy?!

2) use boost::asio (couldn't find a good answer online, if its possible to build boost for C#) or something C#/Net based that can talk to boost::asio. I currently have a boost::asio remote connectivity with my software working.

Any ideas for the above? or new ideas? examples online?

Thanks

Tasos

Views: 1986

Replies to This Discussion

Hi Tasos,

there's basically two solutions I know of that work. We've used both for Rhino .NET SDKs but we no longer like solution #1

  1. C++/CLI. You can create a mixed-mode project in VS that has both unmanaged and managed portions. Grasshopper will deal with the managed bit, treating it like any other GHA library, the unmanaged bit can hook into your analysis library. We used this approach for the old Rhino_DotNET sdk.
  2. PInvoke from C# into C++. This is the approach we use for RhinoCommon and we like it better. It's easier to maintain and you need to learn less new stuff. What you do is write a pure C++ dll that exposes all the functions you need using only simple data types (no classes, just primitive types and arrays). Then you invoke into those methods from C#. RhinoCommon is on gitHub if you want to take a closer look, but unfortunately only the C# part, we're not sharing the C++ wrapper library at this point in time.

--

David Rutten

david@mcneel.com

Poprad, Slovakia

So from what I get the easiest thing is to make a small client dll with the boost:asio client and some simple functions from GH to read/write and use PInvoke..

Link to PInvoke docs/tuts?

Thanks

I'm a little confused about your comment on boost:asio.  Are you trying to have grasshopper communicate with a stand-alone analysis application?  If so, there are networking classes in C# that you can use to perform this (I'm sure a quick google search will result in a ton of examples.)

If the analysis application is your own code, then you may want to consider modifying it to be compiled as a dll instead of an exe.  Once that is done, then you can follow step 2 as outlined by David above (we actually do share the C++ wrapper library also in the github repository).

https://github.com/mcneel/rhinocommon

Thanks,

-Steve

sorry for the confusion :)

Yes, I have 2 options, you are right. 1) compile my software as a dll (lib) or 2) write a boost:asio "wrapped" dll that c# can play with as a network client. the second option came in mind because I already have the asio "server" on my software, so I dont have to manage many builds. (another thing is that my software is multi-platform so the analysis server can be on another machine or outside VM :) )

All is/will be open source so I'll try to keep my code base in one place maybe.

Thanks both for the link. Ill check it.

T

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service