Custome Node Color?

Dear all
There is some way customize the standard color node in my plugin?

something like
node.color(new color.Fromrgb(255, 110, 255);

thanks in advance
carlos

Hi Carlos,

if you want custom display of your components, you’ll have to override the attributes and do the drawing yourself. This seems like a bit of an overkill for just a different colour.

Can I ask what you don’t like about the default colours?

–
David Rutten
david@mcneel.com

Hello David,

Yes, that what I thought, is not possible only change the default color, you have to manage all the states for the node color.

jeje, yes I like the default colors, I just only want to customize the nodes for the plug-in. but at the end if everyone does the same, we will have a Christmas environment.

Thought this forum was dead,
best
c

That is certainly a worry for me. You are of course free to display your components any way you like. You can probably even “trick” the default component into using different colours by swapping out the skin properties just before the native draw and then swapping them back afterwards. That way you don’t have to write any custom layout and rendering code.If you really want, I can show you how that works.

Typically Grasshopper questions are handled on the Grasshopper Ning forum. We moved most McNeel forums over to discourse (i.e. here) but Grasshopper will probably remain separate.

–
David Rutten
david@mcneel.com

Thank you David,

Ye, Would be amazing if you can show me how to customize the Node colors of my plug-in.

thanks in advance
Have a good week.
best
c

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

2 Likes

Thank you very much David,

Have a good week.
regards
C.