Grasshopper

algorithmic modeling for Rhino

Hi,

I'm trying to use an input set of points within a public class, but every time I call it, it says "Type 'obstacles' not defined", even though I have plugged in the list of points 'obstacles'.

Here's some of the code:

Private Sub RunScript(ByVal ini As Double, ByVal iter As Integer, ByVal startpt As List(Of Point3d), ByVal size As Object, ByVal wrap As Boolean, ByVal obstacles As List(Of Point3d), ByRef A As Object, ByRef B As Object)

........

End Sub 

'<Custom additional code>

Public Class Agent

......

Private Function avoid(boids As list(Of boid)) As vector3d
Dim objdist As Double = 50
Dim steer As New Vector3d(0, 0, 0)
Dim count As Integer = 0

For i As Integer = 0 To boids.count - 1
Dim obst As obstacles = obstacles(i)
Dim d As Double = loc.DistanceTo(obstacle)

....

How do I access the obstacle points within this public class? Whats the trick here?

Thanks

Views: 358

Replies to This Discussion

Code is compiled before it is used, so if you're using the type name obstacles that type has to be available at compile-time. The fact that at some point in the future an instance of type obstacle may be passed into the code is not going to help.

Where is the type obstacles defined? Another script component? An external dll?

Thanks for your reply David, you're right, I haven't defined the obstacles type.

I changed it to:

Dim obst As point3d = obstacles(i)

And now its saying that 'obstacles is not declared, may be inaccessible etc etc'

So my original question should have been, if obstacles has been plugged in as an input parameter, how do I use it in a public class? Does it have to be declared within it?

variables defined in the "RunScript" method exist only in the scope of that method. So your classes / objects/ methods in the "Additional Code" section cannot see them. Try declaring your object in "Additional code" and then setting it from inside runscript. It may make sense to pass obstacles as an argument to your class constructor and store it within the class as well, depends on what you're doing. 

Wicked, thanks mate, got it to work in the end - declared it within a sub in the "Additional Code" section

feel like an idiot now!

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service