I have a question regarding custom made Karamba components in visual studio and how to use them in GH.
I generate a Karamba beam element in my custom component and when using it in Grashopper it is defined as a Karamba GH Element. However when I try to add it to my assembly model in GH then I get the error that [A] can not be cast to [B].
I reference my .gha file by making a copy in a custom folder and renaming it to .dll. I also checked that the name of my grasshopper component comes after the name of Karamba in order to load it later in the alphabetical order. I am aware that in the Karamba guide it is suggested that I should reference the .gha file by manipulating the .csproj file. I tried this option as well and it is not working either, throwing me the error that the assembly could not be found.
Does anyone have a suggestion what I might be doing wrong? Appreciate every suggestion.
for some reason karamba.gha is loaded twice during GH startup causing the problem you describe. Copying karamba.gha to karamba.dll is probably the reason. Where do you place your plug-in? Are there duplicate karamba.gha-files somewhere in your default dll search paths? If yes remove them
You could try to unhook ‘Memory load *.GHA…’ in the GrasshopperDeveloperSettings.
My plug-in is placed under the bin/debug path of the development directory and then referenced in through GrashopperDeveloperSettings. The “Memory load” was unhooked already before.
You are correct by assuming that karamba.gha was loaded twice. I changed it to referencing the .gha directly in the .csproj but this gives me another error: “Assembly could not be found”. I assume this has something to do with the loading order, which apparently is very complex for Grashopper as discussed in this stream:
Good morning @karamba3d, myself and @lfuhrimann tried creating a plugin titled ZZZZZ which we found did not load last whether in the bin directory or in the GH Library / Rhino Plugins directory. We assumed that should work as per the Karamba 3D Scripting Guide (1.3.2).
So our next idea was to try as others have suggested creating a shell plugin that points to solvers in a separate DLL, which means Karamba is only called upon on a component solving. However this means custom components can’t utilise the Karamba Types when creating In/Out parameters as that needs to be done in the plugin project, which can’t reliably reference Karamba.
Evidently people have written custom components using this Scripting Guide, so we must be missing a key detail, any ideas?
did you set ‘Copy Local’ to false when referencing ‘karambaCommon.dll’ and ‘karamba.gha’ in you Visual Studio Project?
Did you try out different locations for your plugin (‘Grasshopper\Libraries’, ‘Rhino 6\Plug-ins’)?
Yes I do. @gankeyu, you are correct, you have to be sneaky. I renamed it to Karamba2.dll, referenced that, then renamed it back to Karamba.gha and then changed the reference in the csproj manually to Karamba.gha and it worked perfectly!
@karamba3d, I’m using .Net 4.5.0, I will try 4.6.1
I created a new project called ZZZPlugin in .NET 4.6.1 and have tried various locations as well as Karamba 1.3 and 2.0 (Nightly Build) and I cannot seem to get it to load after Karamba. Could you create a simple example project of a Karamba Plugin that works? That would be extremely helpful as I’m still banging my head against the wall
we will add a corresponding example to the scripting manual.
In the meantime I found this TensionElim_K3D131.rar (519.1 KB) which works with Karamba3D 1.3.1. Maybe it is helpful.
Good morning @karamba3d,
Thanks for the example, I tried the TensionElim Plugin with Karamba 1.3.1 (From Food4Rhino) as well as Karamba 2.0 (From GitHub) with Rhino 6 and 7 and it loaded before Karamba did each time when adding the plugin via the GrasshopperDeveloperSettings path, so still no luck .