algorithmic modeling for Rhino
Hi all,
I have a question about modifying a list, without copying it. I'm not too familiar with how to deal with lists/references in the .Net realm.
I have a lists of points in y, which I wish to modify. It would be preferable to keep the list of object instances to one list (I suppose?), rather then copying it to a new list.
Consider this snippet for example:
For Each point As Point3d In y
Point.Transform(Transform.Translation(0, 0, 10))
Next
A = y
This won't work because I cannot loop through the list accessing the references, and I suppose my 'point' variable is a copy of the instance in the list, and not the instance itself. Is there any way to do this?
Thanks,
Arend
Tags:
Hi Arend,
this is a .Net question. The foreach or For Each (in Vb.Net) statements cannot be used to exchange the current variable in the iteration. You can think of it as though the variable would be read-only (the C# compiler alerts you of this, but it's still possible to change the state of current object).
This is how you could write the snippet above:
For i As Integer = 0 To y.Count - 1
y(i) = y(i) + New Vector3d(0, 0, 10)
Next
A = y
Notice that Grasshopper will copy the List before passing it to your code.
- Giulio
_______________
giulio@mcneel.com
McNeel Europe, Barcelona
Ok, great! So it basicly means makeing a new copy of the object and placing it back in the list.
Thanks, this makes it a lot more clear. Also, thanks for the easier snippet of the transformation. Is there also a way to do an absolute transformation on a point/object/vector? (ie, set the x y and z variables of an existing point?)
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
© 2024 Created by Scott Davidson. Powered by