Grasshopper

algorithmic modeling for Rhino

I have a little problem with this code : 

 

Private Sub RunScript(ByVal y As Surface, ByRef A As Object)  

  Dim los As Random  

Dim nPt As Point3d = y.PointAt(los.NextDouble, los.NextDouble)   

A = nPt 

End Sub

 

prints out : Object reference not set to an instance of an object. (line: 87)

Line 87 is Dim nPt As Point3d = y.PointAt(los.NextDouble, los.NextDouble)

 

What is going on here ? I suppose than problem is in surface y, but how to get it work ? 

Views: 1717

Replies to This Discussion

Dim los As New Random()

 

los was not initialized and thus you could not call los.NextDouble().

 

You should also check y for null, just to be sure:

 

If (y Is Nothing) Then Return

 

Lastly, I highly recommend you construct your Random instance with a constant seed, so that you get the same random values all the time.

 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service