Hi, I’m a newbie in scripting in Visual Studio. I’ve done a very basic Centeroid Plugin but I can’t add the plugin icon. I wrote the resource.$(imageName) then i get error CS0029 Severity Code Description Project File Line Suppression State Error CS0029 Cannot implicitly convert type ‘byte[]’ to ‘System.Drawing.Bitmap’ Att1_S (net48) C:\Users\szeng\source\repos\Att1_S\Att1_SComponent.cs 86 Active".
In addition to this, I cannot debug any code with .net 7. I could only debug with .net 4.8 Framework. Every time I debugged the project I always got an error and .gha file dropped in a “net48” folder in my projects debug folder.
I have attached the full list of errors and warnings below
Error_List.txt (3.0 KB)
PS: I don’t know what file format or information I need to include to help me, so please write if I need to include anything extra.
using Grasshopper;
using Grasshopper.Kernel;
using Rhino.Geometry;
using System;
using System.Collections.Generic;
namespace Att1_S
{
public class Att1_SComponent : GH_Component
{
/// <summary>
/// Each implementation of GH_Component must provide a public
/// constructor without any arguments.
/// Category represents the Tab in which the component will appear,
/// Subcategory the panel. If you use non-existing tab or panel names,
/// new tabs/panels will automatically be created.
/// </summary>
public Att1_SComponent()
: base("Centerroid", "Cntrd",
"Centerroid",
"Workshop", "Geometry")
{
}
/// <summary>
/// Registers all the input parameters for this component.
/// </summary>
protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager)
{
pManager.AddPointParameter("Points", "P", "Points", GH_ParamAccess.list);
}
/// <summary>
/// Registers all the output parameters for this component.
/// </summary>
protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager)
{
pManager.AddPointParameter("Centerroid", "C", "Centerroid", GH_ParamAccess.item);
pManager.AddNumberParameter("Distances", "D", "Distances", GH_ParamAccess.list);
}
/// <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)
{
List<Point3d> points = new List<Point3d>();
DA.GetDataList(0, points);
Point3d centerroid = new Point3d(0, 0, 0);
for (int i = 0; i < points.Count; i++)
{
centerroid += points[i];
}
centerroid /= points.Count;
List<double> distances = new List<double>();
for (int i = 0; i < points.Count; i++)
{
distances.Add(centerroid.DistanceTo(points[i]));
}
DA.SetData(0, centerroid);
DA.SetDataList(1, distances);
}
/// <summary>
/// The Exposure property controls where in the panel a component icon
/// will appear. There are seven possible locations (primary to septenary),
/// each of which can be combined with the GH_Exposure.obscure flag, which
/// ensures the component will only be visible on panel dropdowns.
/// </summary>
public override GH_Exposure Exposure => GH_Exposure.primary;
/// <summary>
/// Provides an Icon for every component that will be visible in the User Interface.
/// Icons need to be 24x24 pixels.
/// You can add image files to your project resources and access them like this:
/// return Resources.IconForThisComponent;
/// </summary>
///
protected override System.Drawing.Bitmap Icon { get { return Properties.Resources.denme; } }
/// <summary>
/// Each component must have a unique Guid to identify it.
/// It is vital this Guid doesn't change otherwise old ghx files
/// that use the old ID will partially fail during loading.
/// </summary>
public override Guid ComponentGuid => new Guid("1600ff72-ff0d-46c6-8213-ec0b046d08c8");
}
}