Hi everyone,
I’m struggling to clear a custom preview from a DisplayConduit when the component’s input is disconnected. My current approach in SolveInstance isn’t working as expected.
I’m using the standard !DA.GetData(0, ref data) || data == null check to check if the input is disconnected but my ClearPreview() function doesn’t seem to execute when the wire is removed, leaving the old preview visible.
using System;
using System.Collections.Generic;
using Grasshopper.Kernel;
using Rhino.Geometry;
namespace Toolpaths.Fdm.Components
{
public class ClearDebug_Component : GH_Component
{
public ClearDebug_Component()
: base("Clear Debug", "ClearDbg",
"A minimal component to debug preview clearing.",
"FDM TP", "DEV")
{
}
protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager)
{
pManager.AddCurveParameter("Curve", "C", "Curve input", GH_ParamAccess.item);
}
protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager)
{
pManager.AddTextParameter("Message", "M", "Debug message", GH_ParamAccess.item);
}
protected override void SolveInstance(IGH_DataAccess DA)
{
Curve curve = null;
if (!DA.GetData(0, ref curve) || curve == null)
{
ClearPreview();
DA.SetData("Message", "Input is invalid, clearing preview.");
return;
}
// If input is valid
DA.SetData("Message", "Input is valid.");
}
private void ClearPreview()
{
// This is the function to be called when input is invalid.
// In the real component, this would clear the conduit.
}
protected override System.Drawing.Bitmap Icon => null;
public override Guid ComponentGuid => new Guid("c1a6c5f1-2a31-4a8e-8b6a-1b3da1b1a0e1");
}
}
When the input for this component is disconnected, the output message doesn’t update to show that the clear function was called.
What is the correct way to detect an invalid or disconnected input to reliably trigger a cleanup function?
Thanks for any advice.
