algorithmic modeling for Rhino
Hi all, I am playing with component in C#. The component is working fine, except that I need to informed all my inputs to get the ouputs.
It seems like if one of the inputs is not informed the component doesn't run..
I would to be free to informed/or not the inputs data.
So if there is an input value returns the output and if the input value is null just don't care.
Can someone help me ?
thx
public class myComponent : Grasshopper.Kernel.GH_Component
{
public myComponent()
: base("MyComponent", "MTC", "My Component", "Extra", "Simple")
{
}
//INPUTS
protected override void RegisterInputParams(Grasshopper.Kernel.GH_Component.GH_InputParamManager pManager)
{
pManager.Register_DoubleParam("Double1", "D1", "Double 1");
pManager.Register_DoubleParam("Double2", "D2", "Double 2");
pManager.Register_DoubleParam("Double3", "D3", "Double 3");
}
//OUPUTS
protected override void RegisterOutputParams(Grasshopper.Kernel.GH_Component.GH_OutputParamManager pManager)
{
pManager.Register_DoubleParam("Double1_out", "D1_out", "Double 1 output");
pManager.Register_DoubleParam("Double2_out", "D2_out", "Double 2 output");
pManager.Register_DoubleParam("Double3_out", "D3_out", "Double 3 output");
}
//SOLVE
protected override void SolveInstance(Grasshopper.Kernel.IGH_DataAccess DA)
{
double data1 = double.NaN;
double data2 = double.NaN;
double data3 = double.NaN;
double data1_out = double.NaN;
double data2_out = double.NaN;
double data3_out = double.NaN;
//if (!DA.GetData(0, ref data1)) { return; }
//if (!DA.GetData(1, ref data2)) { return; }
//if (!DA.GetData(2, ref data3)) { return; }
DA.GetData(0, ref data1);
DA.GetData(1, ref data2);
DA.GetData(2, ref data3);
if (data1 != double.NaN)
{
data1_out = data1 + 10;
DA.SetData(0, data1_out);
}
if (data2 != double.NaN)
{
data2_out = data2 + 10;
DA.SetData(1, data2_out);
}
if (data3 != double.NaN)
{
data3_out = data3 + 10;
DA.SetData(2, data3_out);
}
}
//GUID
public override Guid ComponentGuid
{
get { return new Guid("3fc7a1e5-5645-427c-8525-da87867f4a3f"); }
}
}
Tags:
If I'm following correctly, you want to have your component run when some inputs are not present. You can achieve this by setting them as optional:
pManager.Register_DoubleParam("Double1", "D1", "Double 1");
pManager.Register_DoubleParam("Double2", "D2", "Double 2");
pManager.Register_DoubleParam("Double3", "D3", "Double 3");
pManager[2].Optional = true;
In this case, D3 will not be required to be set before your component runs. You can also set a default value:
pManager.Register_DoubleParam("Double1", "D1", "Double 1" 5.0d);
pManager.Register_DoubleParam("Double2", "D2", "Double 2", 0.0d);
pManager.Register_DoubleParam("Double3", "D3", "Double 3", 10.0d);
The input will hold that value before anything is hooked up. You can use this to set some sensible defaults to ease use.
Cheers,
Chris
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by