Hi , any guide for how to bring .ghuser and .ghcluster files to the compiler and build them with a gha file ?
The only sensible option would be to embed those files as resources and copy them to the disk when the plugin loads.
So then I can’t have a single .gha file as my plugin ?
Yes you can, that single file creates the other files on the disk when it runs. So you only have to distribute one file, but at runtime there will be a collection of files. But who cares about that?
That is exactly the part that I’m looking to write the code for. any tip ?
If you are going to go through the trouble of making a plug-in why not just script the stuff or just use node-in-code. It will run faster (I think).
First you add the existing file to your solution explorer:
Make sure the Build Action
in the properties is set to Embedded Resource
:
You can then access the bytes of that resource through code. For example, I embedded a bunch of 3dm files into my project, they all become part of the dll, and at runtime I write them all to the disk:
ps. the CopyResourceStreamToBytes
method looks like this:
internal static byte[] CopyResourceStreamToBytes(string resourceName)
{
if (string.IsNullOrEmpty(resourceName))
throw new ArgumentException("That is not a valid resource identifier.");
try
{
Assembly assembly = Assembly.GetExecutingAssembly();
using (Stream stream = assembly.GetManifestResourceStream(resourceName))
{
if (stream == null) return null;
using (var memoryStream = new MemoryStream())
{
stream.CopyTo(memoryStream);
return memoryStream.ToArray();
}
}
}
catch (Exception ex)
{
Logger.Add(Level.Exception, "Resource could not be accessed: " + resourceName);
Logger.Add(ex);
return null;
}
}
I can’t also find the method GrasshopperResourceFolder();
I’m just posting the code I use, obviously you’re in a different project so you’ll need to replace the project specific stuff with your own logic.