Grasshopper

algorithmic modeling for Rhino

I need to detect whether a parameter (a point, in this case) is empty or not. Something like an "IsEmpty" component that returns a boolean.

There's probably some obvious way to do this, but I just can't see it this morning :-)

Thanks for any help.

Views: 6075

Replies to This Discussion

If (x = Nothing) Then 

(...)

end if

Can you give us some more details? Do you want to know whether a parameter contains no data, whether the data you can get through DA.GetData is null, whether the data you can get through DA.GetData doesn't exist, ...?

Sorry, here's a little more:

I'm writing a tool that will do some modifications on a surface only if a certain point component is "populated". So I want to somehow generate a boolean that tells me whether that point component is empty (orange) or not.

I was hoping there's a way to do this without scripting, though I'm happy to write a little C# thingie to do it.

Did that help?

Null Item component

Ah! That's exactly what I was looking for, thanks, Daniel! I knew it was there somewhere...

A little sleuthing in C# shows me that an empty point component fed into a C# component ends up as the origin (0,0,0). So I can write something like:

if (x == Point3d.Origin)
A = false;
else
A = true;

And that will do the trick. (Of course, in the unlikely event that the user happens to pick the origin, I'd be in trouble...)

I'd still like to know if there's a way to do this with standard components, though. And/or a script that would work with ANY data type, not just points.

Well that's a problem, Point3d is a value type, so it cannot be null. Whenever I assign a null value to a Point3d field, it gets the default value which is (0,0,0). So it is not possible to detect whether a Point3d parameter has been assigned.

If you really need to check the data, you can look at the VolatileData of the parameter in question to see if the count is zero.

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service