Grasshopper

algorithmic modeling for Rhino

Hey Everyone,

I have a little problem here... I have a set of breps and a list with heights, each brep has a certain height. In the VB-Component I loop through the list of breps and compare the specific height with the height of the next brep - and depending on the result either breps(b) is subtracted from breps(b+1) or the other way around.

The error message is this:

error: Object reference not set to an instance of an object. (line 104, which is the bold one)


I think it has something to do with the conversion of an array of brep to an object of the list of brep, but I couldn't figure it out...

Can anyone help?


Thank you!

Dominik

Private Sub RunScript(ByVal breps As List(Of Brep), ByVal heights As List(Of Double), ByRef A As Object)

    For b As int32 = 0 To breps.Count - 2

      rhino.RhinoApp.WriteLine(b)

      If heights(b) > heights(b + 1) Then

        Dim bool As brep() = brep.CreateBooleanDifference(breps(b + 1), breps(b), 0.1)
        breps(b) = bool(0)

      Else

        Dim bool2 As brep() = brep.CreateBooleanDifference(breps(b), breps(b + 1), 0.1)
        breps(b) = bool2(0)

      End If
    Next

    A = breps

  End Sub

Views: 636

Replies to This Discussion

If brep.CreateBooleanDifference fails it will not give you a Brep in return, bool2 will be null. Since you don't check for null it will then cause a NullReferenceException.

Dim b0 As Brep = Nothing

Dim b1 As Brep = Nothing

If (heights(b) > heights(b+1)) Then

  b0 = breps(b+1)

  b1 = breps(b)

Else

  b0 = breps(b)

  b1 = breps(b+1)

End If

Dim bDiff As Brep() = Brep.CreateBooleanDifference(b0, b1, 0.1)

If (bDiff IsNot Nothing) AndAlso (bDiff.Length > 0) Then

  breps(b) = bDiff(0)

End If

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Thank you so much! It works now...

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service