algorithmic modeling for Rhino
Hi,
I am new to scripting and grasshopper and have been trying to write a script for a simple vb button, which iterates a simple four point curve using loop.
However, my script is only iterates one curve and then repeats it. The random numbers don't iterate themselves after each loop.
My script:
Dim points As New list(Of Point3d)
For i As int32 = 0 To N
'defining the points for cruve
Dim pt1 As New point3d
Dim pt2 As New point3d
Dim pt3 As New point3d
Dim pt4 As New point3d
pt2 = New Point3d(pt1)
pt3 = New Point3d(pt2)
pt4 = New Point3d(pt3)
'equations for generating random points
Dim RandomClass As New Random
Dim RandomNumber As New Integer
Dim RandomNumber2 As New Integer
Dim RandomNumber3 As New Integer
Dim RandomNumber4 As New Integer
Dim RandomNumber5 As New Integer
Dim RandomNumber6 As New Integer
Dim RandomNumber7 As New Integer
Dim RandomNumber8 As New Integer
RandomNumber = RandomClass.Next(1, 10)
RandomNumber2 = RandomClass.Next(-5, 5)
RandomNumber3 = RandomClass.Next(1, 10)
RandomNumber4 = RandomClass.Next(-5, 5)
RandomNumber5 = RandomClass.Next(1, 10)
RandomNumber6 = RandomClass.Next(-5, 5)
RandomNumber7 = RandomClass.Next(1, 10)
RandomNumber8 = RandomClass.Next(-5, 5)
pt1.X = RandomNumber7
pt1.Y = RandomNumber8
pt1.Z = i
pt2.X = pt1.X + RandomNumber
pt2.Y = RandomNumber2
pt2.Z = i
pt3.X = pt2.X + RandomNumber3
pt3.Y = RandomNumber4
pt3.Z = i
pt4.X = pt3.X + RandomNumber5
pt4.Y = RandomNumber6
pt4.Z = i
'generating points for a curve.
points.add(pt1)
points.add(pt2)
points.add(pt3)
points.add(pt4)
Next
a = points
Can anyone help me with this problem?
Thanks
Tags:
sorry,I don't understand what you want.Can you explain it more detail? and can you show the full code you write.
Yeah sure, so I am trying to output a list of random curves which are composed by a list of four points using vb script. However the script I wrote only output one random set of four points. Then repeats the same points N times apart distance 'i' along the z axis.
I accomplished having a random set of curves the first time by using type random, and accomplished the iteration by using loop. However, the loop does not re-randomize the number each time it goes through, thus I end up having the same curve repeated N times. I'm trying to figure it out how to rewrite the script so that through each loop or each iteration of the curve, I will get a new set of points for a new curve, thus have N different curves iterated along the z axis. The output of the vb button is connected to a interpolated curve button.
Here is the full script:
Private Sub RunScript(ByVal N As Integer, ByRef A As Object)
Dim points As New list(Of Point3d)
For i As int32 = 0 To N
'defining the points for cruve
Dim pt1 As New point3d
Dim pt2 As New point3d
Dim pt3 As New point3d
Dim pt4 As New point3d
pt2 = New Point3d(pt1)
pt3 = New Point3d(pt2)
pt4 = New Point3d(pt3)
'equations for generating random points
Dim RandomClass As New Random
Dim RandomNumber As New Integer
Dim RandomNumber2 As New Integer
Dim RandomNumber3 As New Integer
Dim RandomNumber4 As New Integer
Dim RandomNumber5 As New Integer
Dim RandomNumber6 As New Integer
Dim RandomNumber7 As New Integer
Dim RandomNumber8 As New Integer
RandomNumber = RandomClass.Next(1, 10)
RandomNumber2 = RandomClass.Next(-5, 5)
RandomNumber3 = RandomClass.Next(1, 10)
RandomNumber4 = RandomClass.Next(-5, 5)
RandomNumber5 = RandomClass.Next(1, 10)
RandomNumber6 = RandomClass.Next(-5, 5)
RandomNumber7 = RandomClass.Next(1, 10)
RandomNumber8 = RandomClass.Next(-5, 5)
pt1.X = RandomNumber7
pt1.Y = RandomNumber8
pt1.Z = i
pt2.X = pt1.X + RandomNumber
pt2.Y = RandomNumber2
pt2.Z = i
pt3.X = pt2.X + RandomNumber3
pt3.Y = RandomNumber4
pt3.Z = i
pt4.X = pt3.X + RandomNumber5
pt4.Y = RandomNumber6
pt4.Z = i
'generating points for a curve.
points.add(pt1)
points.add(pt2)
points.add(pt3)
points.add(pt4)
Next
a = points
End Sub
'<Custom additional code>
'</Custom additional code>
End Class
Thanks
There are several problems with your code. One of them is that the Random class should really be created either only once, or each time with a different seed. Another problem is that it is not possible to output a List(Of Point3d) which represents a collection of different lists. If you want to output multiple lists, you'll need to create a DataTree(Of Point3d).
I wrote a small script based on yours that outputs a list of curves instead (attached).
Private Sub RunScript(ByVal N As Integer, _
ByVal dx As Interval, _
ByVal dy As Interval, _
ByRef A As Object)
Dim curves As New List(Of Curve)
Dim rnd As New Random(2)For i As int32 = 0 To N
Dim P1 As New Point3d(0.0 + dx.ParameterAt(rnd.NextDouble()), _dy.ParameterAt(rnd.NextDouble()), i)
Dim P2 As New Point3d(P1.X + dx.ParameterAt(rnd.NextDouble()), _dy.ParameterAt(rnd.NextDouble()), i)
Dim P3 As New Point3d(P2.X + dx.ParameterAt(rnd.NextDouble()), _dy.ParameterAt(rnd.NextDouble()), i)
Dim P4 As New Point3d(P3.X + dx.ParameterAt(rnd.NextDouble()), _dy.ParameterAt(rnd.NextDouble()), i)
Dim curve As Curve = Curve.CreateInterpolatedCurve( _
New Point3d(){P1,P2,P3,P4}, 3)
curves.Add(curve)
NextA = curves
End Sub
--
David Rutten
david@mcneel.com
Poprad, Slovakia
Hi John, a possible solution is to replace Dim RandomClass As New Random with Dim RandomClass As New Random(i).
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by