Hi I’m wondering if there is way to hide component itself (maybe with Boolean toggle?) using a python code? I want to be able to turn on and off the visibility of the component itself and wondering if anyone has a idea. Thank you for your help in advance!
why?? I am not aware of a mechanism for hiding or layering components, although this might be something you could try > GH_Component.Hidden Property (rhino3d.com)
Alternatively
- Put your components into a cluster.
- Put a Text Panel on top of your components with a message printed on it
This can be done with metahopper
Hi, you need to override the “attributes” of a component with something empty or you redefine how rendering is supposed to work. For simplicity I show you the empty solution. But I also wonder, what should that solve? You cannot hide anything because you can lock the solver before you hide it…
hide_example.gh (7.1 KB)
using System.Linq;
using Grasshopper.GUI;
using Grasshopper.GUI.Canvas;
using Grasshopper.Kernel.Attributes;
using System.Drawing;
/////
if (hide)
{
GH_Component comp = (GH_Component) GrasshopperDocument.Objects.First(o => o.NickName.Contains(nickname));
_oldAttr = comp.Attributes;
comp.Attributes = new WeirdAttr(comp);
}
if (restore && _oldAttr != null)
{
GH_Component comp = (GH_Component) GrasshopperDocument.Objects.First(o => o.NickName.Contains(nickname));
comp.Attributes = _oldAttr;
}
/////
private static IGH_Attributes _oldAttr = null;
public class WeirdAttr : GH_Attributes<IGH_Component>
{
public WeirdAttr(IGH_Component component) : base(component)
{
}
public override bool HasInputGrip
{
get {return false;}
}
public override bool HasOutputGrip
{
get { return false;}
}
public override void ExpireLayout()
{
}
protected override void Layout()
{
}
public override void AppendToAttributeTree(List<IGH_Attributes> attributes)
{
}
public override GH_ObjectResponse RespondToMouseDown(GH_Canvas sender, GH_CanvasMouseEvent e)
{
return GH_ObjectResponse.Ignore;
}
public override string PathName
{
get {return "Hidden";}
}
public override void SetupTooltip(PointF canvasPoint, GH_TooltipDisplayEventArgs e)
{
}
public override bool InvalidateCanvas(GH_Canvas canvas, GH_CanvasMouseEvent e)
{
return true;
}
protected override void Render(GH_Canvas canvas, Graphics graphics, GH_CanvasChannel channel)
{
}
}
Hi Tom,
Sadly I missed it. What I was trying to achieve was, I’m in a academic field and I have a script that disables editing of grasshopper script after a certain period of time which was developed as part of preventing students to reuse the script for other course work. And one way for them is to get around it is by deleting the component that handles prevention so I was wondering if there’s a way which I might be able to hide it. The script I have is not perfect and they probably can bypass it if they tried but is developed as means to discourage students to take previous years’ script and repurpose it the following year and was wondering if it’s something I could even achieve. If sharing what I was trying to do could cause issues, I understand.
I have undeleted it… This hiding alone is not a problem, but I was reading a couple of other threads from you which indicated you might want to execute code in a hidden way without anyone noticing. Be aware that it’s only a thin line in doing good or bad things and I don’t want to see examples posted by me being part of malicious code.
Thank you very much for your help. I was looking into potential ways of discouraging repurposing files but potential ways to bypass it was either locking the solver or deleting the component that handles checking if file is expired hence I asked the question. As for what I’m trying to do, those technically can be resolved with your answer to this hiding a component method as it doesn’t need to be perfect and I also do not want my post to give method/ideas for any malicious actions to others. If you can leave a comment in my prevention of deletion thread, pointing to your response to this issue or mentioning the issue, I’ll mark that post as a solution as I don’t want it to get answered further to avoid trouble. Thank you very much again for your help.