C# getting input parameter if its null

Hi,

I am trying to make a simple code that reads if the input line is no input, return false.
My code doesnt return the false value if the line Component input is “No parameter input found”.

How can i fix this?

Here is the simple code:

private void RunScript(Line Data, object x, object y, ref object A)
  {
    Print(YesOrNo(Data).ToString());
  }

  // <Custom additional code> 
  public bool YesOrNo(Line input)
  {
    if(input == null){
      return false;
    }
    return true;

  }

Regards,

Giorgio

Maybe the attached can shed some light?

Objects_GetTypeName_V1.gh (7.8 KB)

1 Like

Rhino.Geometry.Line is a struct, so by definition can’t be null.

EDIT:
Maybe you prefer that approach:

 public bool InputHasData(IGH_Component comp, int index)
 {
    return comp.Params.Input[index].VolatileDataCount > 0;
 }
1 Like

Hi,
You used a “Type hint” on your “Data” input: Line.
Try to add a “A = Data;” in your script, you’ll find that your originally “null” object is converted to a 0-length line with start and end points to 0,0,0 … so it is never “null”.
Rhino.Geometry.Line is a non-nullable type, so from inside your c# viewpoint “Data” is always ok.

You can input your lines as GeometryBase (which is nullable, it seems…) and lately cast them as LineCurve type when you need it.
line.gh (10.2 KB)

1 Like

Thanks for all the replys! Helps a lot to get what i want. Thanks again!