Grasshopper

algorithmic modeling for Rhino

Hello again,

I'm trying to change the appearance of a gh component/capsule on the canvas. In particular, I am not trying to specify a new layout altogether but only to add a few extra items to the layout automatically created by gh. For instance, in the example below, I am simply trying to draw a circle around a component.

First, I am creating custom attributes:

public class CustomParameterAttributes : GH_Attributes<MyComponent>
{
public CustomParameterAttributes (SbpOpt owner) : base(owner) { }

public override void ExpireLayout()
{
base.ExpireLayout();
}

protected override void Layout()
{

base.Layout();
}

protected override void Render(GH_Canvas canvas, Graphics graphics, GH_CanvasChannel channel)
{
base.Render(canvas, graphics, channel);
if (channel == GH_CanvasChannel.Objects)
{
PointF p = this.Pivot;
System.Drawing.Pen pen = new System.Drawing.Pen(Brushes.AliceBlue);
graphics.DrawEllipse(pen, (int)p.X, (int)p.Y, 200, 200);

}
}

public override GH_ObjectResponse RespondToMouseDown(GH_Canvas sender, GH_CanvasMouseEvent e)
{
return base.RespondToMouseDown(sender, e);
}

}

In my component, I am overriding the CreateAttributes() method:

public class MyComponent: GH_Component
{

//this doesn't draw my added information:

public override void CreateAttributes()
{

base.CreateAttributes();
List<IGH_Attributes> atts = new List<IGH_Attributes>() { new CustomParameterAttributes(this) };
base.Attributes.AppendToAttributeTree(atts);
}

//or, the following replaces base attributes with mine, but doesn't draw the default layout.

public override void CreateAttributes()
{
m_attributes = new CustomParameterAttributes(this);
}

}

Is there a way I can create the initial layout in the default way (populating inputs, outputs, nick name etc) and add extra objects later on? I would have thought calling base.Layout() and base.Render() in my attribute would do just that, this doesn't seem to do the job.

For reference, the code shown above is derived from the custom attributes chapter in the SDK and a few posts on this forum, including

http://www.grasshopper3d.com/forum/topics/create-radio-button-on-gr...

http://www.grasshopper3d.com/forum/topics/sdk-tutorial-custom-attri...

Thanks for any help!

Daniel

Views: 2307

Replies to This Discussion

Hi Daniel,

I think you are doing things correctly i.e. the second option

//or, the following replaces base attributes with mine, but doesn't draw the default layout.

public override void CreateAttributes()
{
m_attributes = new CustomParameterAttributes(this);
}

I think the mistake you made is you used the wrong base class for the custom attributes. Instead of GH_Attributes use  Grasshopper.Kernel.Attributes.GH_ComponentAttributes

I have attached an example based on yours. Hope this helps you out.

 

Attachments:

Jason, thanks very much! Works like a treat!

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service