Grasshopper

algorithmic modeling for Rhino

So I was inspired by the hackers guide to Karamba, and set out to do some coding using it in a c# project. It seemed to be going well, but I have hit a point where the wrapper is throwing errors(usually a bad sign).

For example, instead of calling the Component_MeshToShell_GUI, I call:

Component_MeshToShell.solve(new List<Point3d>(), new List<Mesh>() { mesh }, limit_dist, new List<string>() { "shell" }, out List<Point3d> out_points,
out List<GrassShell> ghShells, out string info);

Inside this is a call to the feb.NKDTree(exposed via ILSpy), which fails with some reference to a missing entry point, SWIG, blah blah (the wrapper). Possibly I skipped a step that loads something?

It seemed a bit too easy, so I am not surprised. I am trying to do this directly in rhino, not in GH, so I am purposely cutting out most of the steps that go back and forth from GH. 

Views: 746

Replies to This Discussion

Hi Wes,

did you check whether your Karamba works in Grasshopper?

Did you maybe install the 64bit version of Karamba and tried to use it from within the 32bit version of Rhino (or vice versa) ?

Best,

Clemens

Hi Clemens,

   Thanks for getting back to me. Karamba does work inside grasshopper, and I am using 64 bit in both cases. One thing I noticed, is that I did have a little bit of trouble following your instructions on how to reference karamba.gha in my VS project. My workaround was simply to rename karamba.gha to .dll, and then VS seemed happy. In case it helps, I will attach my full code(at least the part that resides in my RhinoCommand). Another thought I had, was that in the python and java examples, I see where you explicitly load the license. I have not done anything in that regard in the attached code.

Also, the exact error is :

System.TypeInitializationException: 'The type initializer for 'feb.karambaPINVOKE' threw an exception.'

Thanks again,

Wes

Attachments:

Just in case this file helps as well...

Attachments:

Hi Wes,

sorry for my late reply.

Could you send me the 'SuperKarambaPlugIn.cs'-file so that I can compile and test the whole project?

The error message you describe indicates that a C++ function which is called in the C# part is missing. The C++ part has the name 'karamba.dll', resides in 'C:/Windows' and thus lies on the standard search path for dynamic link libraries. Maybe the fact that you rename 'karamba.gha' to 'karamba.dll' is part of the problem. Try the following: After  renaming 'karamba.gha' to 'karamba.dll' and referencing it in the msvc project open the csproj-file with a text editor and change 'karamba.dll' again to 'karamba.gha'.

Best,

Clemens

Thanks,

  I will try this and also get the full package for you.

sorry it took a while to get back on this. So I tried the renaming, and I think it may have helped. Nonetheless I have been going in a few circles. One thing I have verified, is that once you rename, even though you now reference the karamba.gha file, you must remove any karamba.dll file from the same folder (else you get the PInvoke error even when simply trying to use GH). Once you remove that typical example files on the website work fine in GH. Probably this is because it doesn't look to the C:\Windows to find the real karamba.dll.

I was still getting very cryptic errors in my VS project, so I thought it would be good to just try the example GH_Component you provide. I opened the solution and corrected the references (in the case of the karamba.gha just manually editing the csproj). When I build and run rhino, GH, I was surprised to throw an error trying to load the component! 

This error also throws without VS, as it tries to load the TensionElimComponent

Object: TensionElimComponent (level 2)
{
Could not load file or assembly 'karamba, Version=1.14.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
FileNotFoundException
}

Once I get into grasshopper though the sketch runs fine. But I cannot set a breakpoint inside the solve instance method. 

As far as the cryptic error in my VS (non GH project) it also appears to be failing to load something, but it doesn't even get to the PInvoke error. It now simply won't run the command unless I comment out all refs to karamba types(oddly though it gives no error in VS).

So now I sort of have two issues! I am attaching the sln for the non gh project. As far as why the TensionElimComponent won't run either, I am sure it is a related thing. I am assuming it wouldn't matter that my path is C:\Program Files\Rhinoceros 5 (64-bit)\Plug-ins (it seems to normally expect 5.0 instead of 5). And also that none of this would be license related? I will keep trying to just get a simple reference to work that then calls into the dll.

Attachments:

Hi Wes,

I think I found the problem: you used version 4.6 of the .NET framework. Grasshopper for Rhino5 and also Karamba are compiled under .NET version 4.0. Grasshopper for Rhino6 and also Karamba 1.3.0 for Rhino 6 are compiled under .NET version 4.5. 

You can switch the .NET version by right-clicking on the project in the MSVC Solution Explorer, then select 'Properties', 'Application' then 'Target framework'.

In the attached project I adapted the calls to Karamba to Karamba version 1.3.0. and .NET Framework 4.0.

I hope that helps.

Best,

Clemens

P.S.: Sorry for my late reply.

Attachments:

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service