Input in resizable component

Hi all ,

I’m trying to make a custom component (using C#) which is resizable, so I’m making a attribute class that inherits from GH_ResizableAttributes. It’s a bit of a struggle atm, since I’d like my component to have a input, but I can’t get it to work. By overriding the Render-function, I can draw an input grip, but I can’t use it… It’s like Grasshopper doesn’t know it’s there, even though I’ve also added the input in the component-class.

I’m thinking I might need to add something in the Layout-function too, but I can’t figure out how/what? So I would really appreciate if anyone has any inputs on this!

In my GH-component class I have;

public class MyComponent: GH_Component
………

protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager)
{
pManager.AddIntegerParameter(“Numbers”, “Numbers”, “Numbers”, GH_ParamAccess.list);
}

Then in my attributes-class:

public class ComponentsAttributes: GH_ResizableAttributes

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)
        {
            GH_Palette palette = GH_Palette.Normal;
            GH_Capsule capsule = GH_Capsule.CreateCapsule(Bounds, palette);
            capsule.AddInputGrip(this.InputGrip);
            capsule.Render(graphics, Selected, Owner.Locked, true);
        }

}

1 Like

Solved this by changing my GH_Component to a GH_Param! GH_Param however has one output too, by default. Now, by overriding the Render-function I don’t draw the output but it’s still there - I can still grap an output that isn’t drawn.

Do anyone know how to remove the output completely?

output

I guess you’re looking for HasOutputGrip.

namespace Resizable
{
    public class ResizableComponent : GH_Param<GH_Number>
    {
        public ResizableComponent() : base(new GH_InstanceDescription("Resizable",
            "Resizable", "Resizable Component", "Category", "subcategory"))
        {
        }
        public override void CreateAttributes()
        {
            m_attributes = new ResizableComponentAttributes(this);
        }
        protected override Bitmap Icon => null;
        public override Guid ComponentGuid => new Guid("6b5273e5-e6b6-4a08-a5b8-4cbf5c7f7cb1");
    }
    public class ResizableComponentAttributes : GH_ResizableAttributes<ResizableComponent>
    {
        public ResizableComponentAttributes(ResizableComponent owner) : base(owner)
        {
            Bounds = new Rectangle(0, 0, 150, 150);
        }
        public override bool HasOutputGrip => false;
        protected override Size MinimumSize => new Size(50, 50);
        protected override Padding SizingBorders => new Padding(6);
        protected override void Layout()
        {
            Bounds = new RectangleF(Pivot, Bounds.Size);
        }
        protected override void Render(GH_Canvas canvas, Graphics graphics, GH_CanvasChannel channel)
        {
            if (channel == GH_CanvasChannel.Wires)
                RenderIncomingWires(canvas.Painter, Owner.Sources, Owner.WireDisplay);
            else if (channel == GH_CanvasChannel.Objects)
            {
                var capsule = GH_Capsule.CreateCapsule(Bounds, GH_Palette.Normal, 5, 30);
                capsule.AddInputGrip(InputGrip.Y);
                capsule.SetJaggedEdges(false, true);
                capsule.Render(graphics, Selected, Owner.Locked, true);
                capsule.Dispose();
            }
        }
    }
}

Resizable.zip (24.0 KB)

2 Likes

Yes, perfect! Now it’s working, thank you! :sunny: