Grasshopper

algorithmic modeling for Rhino

Sorry if this has been addressed before, but I hadn't found anything. Is there a simple way of checking whether an input parameter for a VB script component has been set (with a type hint selected). For example, when a type hint of 'Double' is selected and I test it by saying "If x Is Nothing..." then I get the error "Error (BC30020): 'Is' operator does not accept operands of type 'Double'. Operands must be reference or nullable types."

Similar issue when the type hint is Point3d, except when I go to check it using either point.IsValid or IsDBNull(point), it doesn't catch it because it seems like by default, when no value is entered, it gets set as {0,0,0}. See the simple script I threw together below. It should be triggering those error messages when you disconnect the inputs, but it doesn't.

Thanks!

Views: 7239

Attachments:

Replies to This Discussion

Will,

 

For doubles, floats ect ect the correct syntax would use the "=" sign instead.

 For example

    If x = Nothing Then

      x = 10.00

    End If

    A = x

for other data types you can use "is"

 

Best,

M.

Ah, of course. I tried doing that with the Point3d object too (If point = Nothing...), and while it works in general, it does not work when a {0, 0, 0} point is connected to the input. Is there any way to differentiate between a legitimate {0, 0, 0} point and no connection at all?

It's not really possible for things like doubles and integers because they cannot be null.

--

David Rutten

david@mcneel.com

Just realized that the above (If x = Nothing...) doesn't work for Doubles if the value connected to the input parameter is 0 since it equates 0 with Nothing. Same issue with the Point3d object (and a {0, 0, 0} point). So there's no way to tell if an input is connected to anything or not?

Hmmm.

I can replicate that. Weird. Maybe David can shed some light on this one.

 

Best,

M.

Sure:

It's not really possible for things like doubles and integers because they cannot be null.

--

David Rutten

david@mcneel.com

Hi Will,

I am not sure if this is the most straightforward solution, but there is a property called SourceCount for Grasshopper parameters, which tells you the number of data sources that particular parameter has.

So you can check whether an input parameter has 0 sources, which would imply that no wire is connected to it. The code would be something like this:

Dim index As Int32
index = Component.Params.IndexOfInputParam("x")

If Component.Params.Input.ElementAt(index).SourceCount = 0 Then
'blah blah

Excellent! While that wasn't exactly what I was looking for, it put me on the right path to find (in the Grasshopper SDK) what I was looking for:

If Component.Params.Input.ElementAt(Component.Params.IndexOfInputParam("x")).DataType = 1 Then
Print("Error: x has no data input")
End If

Note for novices like myself, a DataType of 2 means it has an internal/persistent value set by the user, and a DataType of 3 means that the input is connected to an external source.

I would think there'd be a simpler way to check for this though? Like "If x.DataType = 1 Then..."

FYI, my updated null_test script (try connecting/disconnecting wires and experimenting with different values other than 0).

Attachments:

Ah cool, I learned something new today!

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service