Grasshopper

algorithmic modeling for Rhino

Hi, I'm pretty new to using VB...but I think it is the proper way to go for my current problem.

Essentially, I have a bunch of curves that are all different sizes which I need to shrink to standard sizes. I've been doing this up until now using a very rudimentary VB script I wrote that looks like this:

If x < .8875 Then
A = .75
ElseIf x >= .8875 And x < 1.025 Then
A = .8875
ElseIf x >= 1.025 And x < 1.1625 Then
A = 1.025

.......and so on and so on

You can see how clumsy this is. What I would like to do is take this script and make it dynamic; so I can plug in a step size and let it run through a loop of some kind so if I decide we want 20 unique sizes instead of 10, I don't have to go in and re-work all that cumbersome code.  I've tried this with For loops and Do While loops...but I must be missing something cause it isn't working. Currently my loop looks like this: (n is number of steps/unique members, min is minimum size, and steps is the increment of length from n to n+1)

For i = 0 To i = n - 1
  If l >= min + steps * i And l < min + steps * (i + 1) Then
    A = min + steps * i - .05
  Else i = i + 1
  End If
Next

The code works, but doesn't loop. Can anybody point me in the right direction to fix this?

Views: 908

Replies to This Discussion

For i = 0 To i = n - 1

should be

For i = 0 To n - 1

i = n-1 will evaluate to False (or True, depending on what n is). True and False will be converted into 1 and 0 respectively.

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Worked! Thanks David. I guess I really showed my inexperience with scripting on this one....

On top of all that, turns out my 'Else i = i+1' there at the end made it so I was only running the loop for even iterations (good to know for future reference).

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