I created special attributes for the EndPoints component, but only overrode two palette styles (hence the central component capsule is still black). It will look like this (unselected and selected):
You’ll have to create new attributes that derive from GH_ComponentAttributes, assign those attributes by overriding CreateAttributes() on your component and then hijack the Render method:
public class Attributes_EndPoints : Grasshopper.Kernel.Attributes.GH_ComponentAttributes
{
public Attributes_EndPoints(IGH_Component component) : base(component) { }
protected override void Render(GH_Canvas canvas, Graphics graphics, GH_CanvasChannel channel)
{
Grasshopper.GUI.Canvas.GH_PaletteStyle styleStandard = null;
Grasshopper.GUI.Canvas.GH_PaletteStyle styleSelected = null;
if (channel == GH_CanvasChannel.Objects)
{
// Cache the current styles.
styleStandard = GH_Skin.palette_normal_standard;
styleSelected = GH_Skin.palette_normal_selected;
GH_Skin.palette_normal_standard = new GH_PaletteStyle(Color.HotPink, Color.Maroon, Color.DarkRed);
GH_Skin.palette_normal_selected = new GH_PaletteStyle(Color.SkyBlue, Color.DarkBlue, Color.Black);
}
// Allow the base class to render itself.
base.Render(canvas, graphics, channel);
if (channel == GH_CanvasChannel.Objects)
{
// Restore the cached styles.
GH_Skin.palette_normal_standard = styleStandard;
GH_Skin.palette_normal_selected = styleSelected;
}
}
}
public class Component_EndPoints : GH_Component
{
public Component_EndPoints()
: base("End Points", "End", "Extract the end points of a curve.", "Curve", "Analysis") { }
public override void CreateAttributes()
{
base.m_attributes = new Attributes_EndPoints(this);
}
protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager)
{
pManager.AddCurveParameter("Curve", "C", "Curve to evaluate", GH_ParamAccess.item);
}
protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager)
{
pManager.AddPointParameter("Start", "S", "Curve start point", GH_ParamAccess.item);
pManager.AddPointParameter("End", "E", "Curve end point", GH_ParamAccess.item);
}
protected override void SolveInstance(IGH_DataAccess DA)
{
Curve crv = null;
if (!DA.GetData(0, ref crv)) { return; }
DA.SetData(0, crv.PointAtStart);
DA.SetData(1, crv.PointAtEnd);
}
public override GH_Exposure Exposure
{
get { return GH_Exposure.primary; }
}
public override Guid ComponentGuid
{
get { return new System.Guid("{11BBD48B-BB0A-4f1b-8167-FA297590390D}"); }
}
protected override System.Drawing.Bitmap Icon
{
get
{
return CurveComponents.Properties.Resources.CurveEnds_24x24;
}
}
}
For the above to work you’ll need to import the Grasshopper.GUI.Canvas and System.Drawing namespaces.
–
David Rutten
david@mcneel.com