I have a input param called A which will refresh every 50ms. But I don’t want my component to run every 50ms. I hope that my component run only if I disenable and enable it.
You could use a data dam before the input param A in the script.
Else you will need to add something like a boolean input along with a global flag on whether to update or not along with a global variable for what it will be set as.
public class componentClass : GH_Component
{
private bool UpdateOut { get; set; }
private double Val {get; set;}
public PortalFrameStructureInput()
: base(...)
{
UpdateOut = true;
}
protected override void RegisterInputParams(GH_InputParamManager pManager)
{
pManager.AddBooleanParameter("Run", "R", "Run the Stript", GH_ParamAccess.item, false);
pManager.AddNumberParameter("A", "A", "A", GH_ParamAccess.item);
}
protected override void RegisterOutputParams(GH_OutputParamManager pManager)
{
pManager.AddNumberParameter("A", "A", "A", GH_ParamAccess.item);
}
protected override void ExpireDownStreamObjects()
{
if (UpdateOut)
{
Params.Output[0].ExpireSolution(false);
}
}
protected override void SolveInstance(IGH_DataAccess DA)
{
DA.DisableGapLogic();
Boolean run = false;
DA.GetData(0, ref run);
Double A = 0;
DA.GetData(1, ref A);
if (UpdateOut)
{
DA.SetData(0, Val);
UpdateOut = false;
return;
}
if (run)
{
//"run solver:
//Val = new value;"
}
DA.SetData(0, Val);
if (run)
{
UpdateOut = true;
var doc = OnPingDocument();
doc?.ScheduleSolution(5, Callback);
}
}
private void Callback(GH_Document doc)
{
if (UpdateOut)
{
ExpireSolution(false);
}
}
2 Likes
Casue data dam only has a few option so it might be easy to use but not my selection. And it seems that globle flag might be a better choice. Thank you.