Hi I am new in PlugIn development and i have done a simple component to extract TreePaths, intended for Rhino7 using .NET Framework. When i debug it it works fine, but when i tried to add an icon to the component it gives me this error:
Severity Code Description Project File Line Suppression State
Error (active) CS0029 Cannot implicitly convert type ‘byte[]’ to ‘System.Drawing.Bitmap’ MothGHPlugin C:\Users\carme\Documents\MothGrasshopperPlugIn\MothGHPlugin\TreePathsComponent.cs 76
Also I have noticed that when I upload an image as a resource i dont have the bitmap option as a type eventhough I have noticed some other tutorials and sample projects i have seen have the type bitmap on their images for icons.
I also have tried to use .ico, and bitmaps but it also gives me errors. I know that .NET saves images as bytes but not sure how to address this if my project target is .NET Framework. 4.8?
Thank you in advance!!
PS: please let me know if I need to include anything extra.
using System;
using System.Collections.Generic;
using Grasshopper;
using Grasshopper.Kernel;
using Grasshopper.Kernel.Data;
using Grasshopper.Kernel.Types;
using Rhino.Geometry;
namespace MothGHPlugin
{
public class TreePathsComponent : GH_Component
{
/// <summary>
/// Initializes a new instance of the TreePathsComponent class.
/// </summary>
public TreePathsComponent()
: base("TreePaths", "TPaths",
"Extracts paths from a Data Tree",
, "Data")
{
}
/// <summary>
/// Registers all the input parameters for this component.
/// </summary>
protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager)
{
pManager.AddGenericParameter("DataTree", "T", "Tree to get paths", GH_ParamAccess.tree);
}
/// <summary>
/// Registers all the output parameters for this component.
/// </summary>
protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager)
{
pManager.AddIntegerParameter("TreePaths", "P", "Paths of T", GH_ParamAccess.tree);
}
/// <summary>
/// This is the method that actually does the work.
/// </summary>
/// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
protected override void SolveInstance(IGH_DataAccess DA)
{
// Define a GH_Structure to hold the data tree
GH_Structure<IGH_Goo> T = null;
// Load the input tree using GetDataTree (specific for tree access)
if (!DA.GetDataTree(0, out T))
return;
//Component Code
// Algorithm
// Initialize the result list
DataTree<int> paths = new DataTree<int>();
foreach (var p in T.Paths)
{
List<int> numbers = new List<int>();
foreach (int num in p.Indices)
{
numbers.Add(num);
}
paths.AddRange(numbers, p);
}
//Output
DA.SetDataTree(0, paths);
}
/// <summary>
/// Provides an Icon for the component.
/// </summary>
protected override System.Drawing.Bitmap Icon => MothGHPlugin.Properties.Resources.TreePaths;
/// <summary>
/// Gets the unique ID for this component. Do not change this ID after release.
/// </summary>
public override Guid ComponentGuid
{
get { return new Guid("B5214C83-E386-475C-A9CC-F98B4A5D72C6"); }
}
}
}