Hello
How to hide an output grip if this possible?
You’d have to supply your own attributes. Is this for a component or a custom parameter?
If the former, it’ll be very hard, if the latter, it should be fine.
Thanks @DavidRutten
It is for a component to preview images, but if it’s too hard that’s fine, I’ll keep it as is
Is there a way to disable Always draw name
Is there ever more than one input? If not, you should be using a parameter instead of a component. Then overriding the attributes from scratch is a lot easier.
There is just one input , creating parameter to make this sounds good but i have no idea how to do it,
and i don’t find a simple example to start with it.
I try this but i have problems, Owner.Value = null
and the input wire is invisible
using System;
using System.Collections.Generic;
using Grasshopper.Kernel;
using System.Drawing;
using Grasshopper.GUI;
using Grasshopper.GUI.Canvas;
using Grasshopper.Kernel.Types;
namespace WizardComponent
{
public class PreviewImageObject : GH_Param<IGH_Goo>
{
public PreviewImageObject() :
base(new GH_InstanceDescription("Bitmap", "Bitmap", "Bitmap data", "Display", "Wizard"))
{ }
public override void CreateAttributes()
{
m_attributes = new PreviewImageObjectAttributes(this);
}
protected override Bitmap Icon
{
get
{
return Properties.Resources.imC;
}
}
public override GH_Exposure Exposure
{
get
{
return GH_Exposure.primary;
}
}
public override System.Guid ComponentGuid
{
get { return new Guid("C2454A89-5CAD-42DC-880D-204092A740D2"); }
}
private IGH_Goo m_value;
public IGH_Goo Value
{
get { return m_value; }
set { m_value = value; }
}
protected override void CollectVolatileData_Custom()
{
VolatileData.Clear();
AddVolatileData(new Grasshopper.Kernel.Data.GH_Path(0), 0, Value);
}
/*/
public override bool Write(GH_IO.Serialization.GH_IWriter writer)
{
CheckBmp(Value);
writer.SetDrawingBitmap("Bitmap", inputImage);
return base.Write(writer);
}
public override bool Read(GH_IO.Serialization.GH_IReader reader)
{
reader.GetDrawingBitmap("Bitmap");
return base.Read(reader);
}
Bitmap inputImage;
void CheckBmp(IGH_Goo obj)
{
Bitmap bitmap = default;
if (obj != null)
{
Type dataType = obj.GetType();
if (obj.TryGetBitmap(ref bitmap))
{
inputImage = bitmap;
}
else if (dataType == typeof(GH_String))
{
GH_String ghString = (GH_String)obj;
inputImage = (Bitmap)System.Drawing.Image.FromFile(ghString.Value);
}
}
}
/*/
}
public class PreviewImageObjectAttributes : GH_Attributes<PreviewImageObject>
{
public PreviewImageObjectAttributes(PreviewImageObject owner)
: base(owner)
{
}
private const int ButtonSize = 96;
protected override void Layout()
{
Pivot = GH_Convert.ToPoint(Pivot);
Bounds = new RectangleF(Pivot, new SizeF(ButtonSize , ButtonSize));
}
protected override void Render(GH_Canvas canvas, Graphics graphics, GH_CanvasChannel channel)
{
if (channel == GH_CanvasChannel.Objects)
{
//Render output grip.
GH_CapsuleRenderEngine.RenderOutputGrip(graphics, canvas.Viewport.Zoom, OutputGrip, true);
GH_CapsuleRenderEngine.RenderInputGrip(graphics, canvas.Viewport.Zoom, InputGrip, true);
GH_Capsule buttonb = GH_Capsule.CreateCapsule(Bounds, GH_Palette.Transparent, 1, 1);
buttonb.Render(graphics, Color.LightGray);
buttonb.Dispose();
if (Owner.Value != null)
{
CheckBmp(Owner.Value);
graphics.DrawImage(inputImage, Bounds.Location);
}
else
graphics.DrawImage(Properties.Resources.prev, Bounds.Location);
}
}
Bitmap inputImage;
void CheckBmp(IGH_Goo obj)
{
Bitmap bitmap = default;
if (obj != null)
{
Type dataType = obj.GetType();
if (obj.TryGetBitmap(ref bitmap))
{
inputImage = bitmap;
}
else if (dataType == typeof(GH_String))
{
GH_String ghString = (GH_String)obj;
inputImage = (Bitmap)System.Drawing.Image.FromFile(ghString.Value);
}
}
}
}
}
Problem of wires solved but still can’t read input data
else if (channel == GH_CanvasChannel.Wires)
{
RenderIncomingWires(canvas.Painter, Owner.Sources, Owner.WireDisplay);
}
I find a solution in the example posted by @DavidRutten in this old topic
How can I fix this? I moved the input grip, but the wire is still plugged into the old position.
protected override void Layout()
{
CheckBmp(Owner.Value);
if (inputImage != null)
image = inputImage;
else
return;
Pivot = GH_Convert.ToPoint(Pivot);
int width = image.Width;
int height = image.Height;
Bounds = new RectangleF(Pivot, new SizeF(width, height));
}
protected override void Render(GH_Canvas canvas, Graphics graphics, GH_CanvasChannel channel)
{
var input_ = new PointF(Bounds.Left, Bounds.Top + 10);
if (channel == GH_CanvasChannel.Objects)
{
GH_CapsuleRenderEngine.RenderInputGrip(graphics, canvas.Viewport.Zoom, input_, true);
GH_Capsule buttonb = GH_Capsule.CreateCapsule(Bounds, GH_Palette.Transparent, 1, 1);
buttonb.AddInputGrip(input_);
buttonb.Render(graphics, Color.FromArgb(100, 180, 180, 180));
buttonb.Dispose();
graphics.DrawImage(image, Bounds.X, Bounds.Y, image.Width, image.Height);
}
else if (channel == GH_CanvasChannel.Wires)
{
RenderIncomingWires(canvas.Painter, Owner.Sources,GH_ParamWireDisplay.faint);
}
else
{
base.Render(canvas, graphics, channel);
}
}
Right now i don’t find a solution , i tried this but didn’t work
RectangleF gripRect = Bounds;
gripRect.Width = Bounds.Width;
gripRect.Height = 20;
GH_ComponentAttributes.LayoutInputParams((IGH_Component)Owner, gripRect);
I stay with the component, i find a solution to remove Always draw name …
by using: public override bool IconCapableUI => false;
And i override the icon with 1 pixel image:
comp.MutableNickName = false;
comp.SetIconOverride(new Bitmap(1,1));