Grasshopper

algorithmic modeling for Rhino

i have this problem with vb lists in grasshopper:

-i introduce SPRINGS as input List(Of On3dPoint),
-i declare REJILLA as input List(Of On3dPoint),
-then i equal REJILLA to SPRINGS
-i operate with REJILLA
-and when i look at the output values for SPRINGS and REJILLA, both
are modified by the operator!
so my question is:
how can i introduce a list in vb and keep it non-modified (while i
operate with another one created in vb that has inherited its values)

the script:

thanks a lot!
jorge

Sub RunScript(ByVal puntos As List(Of On3dPoint), ByVal springs As List
(Of On3dPoint), ByVal k As Double, ByVal m As Double, ByVal iter As
Integer, ByVal num_f As Integer, ByVal num_c As Integer)
Dim i As Int16
Dim p0 As New On3dPoint()
Dim cont As Int16
Dim num_i As Integer
num_i = num_f + 2
Dim num_j As Integer
num_j = num_c + 2
Dim max_i As Integer
max_i = num_f - 1
Dim max_j As Integer
max_j = num_c - 1
Dim j As Integer
Dim p_max As Integer
Dim p_list As New List(Of On3dPoint)
p_max = springs.Count() - (num_f + num_c)
Dim rejilla As New List(Of On3dPoint)
For i = num_j To p_max Step num_j - 1
For j = i To i + num_c - 2
rejilla.add(springs(j))
Next
Next
While cont < iter
For i = 0 To rejilla.count() - 1
rejilla(i).x += 3
rejilla(i).y += 4
rejilla(i).z += 6
print("posicion " & rejilla(i).x & " " & rejilla(i).y & " " &
rejilla(i).z)
Next
cont += 1
End While

SP = springs
RJ = rejilla
PT = puntos

Views: 488

Replies to This Discussion

Rather than adding items from the old list to the new list, create a new point and use the old list item values to generate the new point data:

Sub RunScript(ByVal inPt As List(Of On3dPoint))

Dim ptList As New List (Of On3dPoint)
For i As Int32 = 0 To inPt.Count() - 1
Dim tPt As New On3dPoint
tPt.x = inPt(i).x
tPt.y = inPt(i).y
tPt.z = inPt(i).z

ptList.Add(tPt)

tPt.z = Sin(i) * 2
Next

A = ptList
B = inPt

End Sub
Attachments:
A bit tricky, but just like Dirk mentioned, you will need to create new point for each point on the list. The way you wrote it basically "reference" points from the old list rather than create "new" points and therefore any changes get applied to "both" lists.

Hope this helps.
I agree,

I've just broken down started to learn vb (i see no sign of python coming back in the near term). Is Dirk's example really the only way to do this?

is there no way of making a copy statement?

inPt = ptList xxxx ?

- egads that's an annoying way to copy stuff. - I yearn for ruby! (dup or clone)

also, if your trying to copy a vector I've found that multiplying the source vector by 1 during the assignment breaks the referencing.

also, as is implicit in your example, this referencing 'feature' survives the 'byval' statement when creating sub's so lookout!
All elements that come into the VB Component are ByVal, inPt becomes a duplicated list of points from the input component.

Ok, I missed something here - tPt.Set(inPt(i)) works fine at duplicating points.

I suppose you could also send the inPt to a Function as ByVal?
sorry - it was in fact me that missed something (sub run script) I was referring to helper sub's created outside of run script in the additional subs and type definitions area.

I read somewhere that is referencing override is an optimization that the compiler creates... I'm still fairly foggy on how this all works (obviously).

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