algorithmic modeling for Rhino
Hi guys,
I want to do this, as Sort List component do it...
I have this:
Private Sub RunScript(ByVal x As DataTree(Of Double), ByVal y As List(Of Integer), ByRef A As Object)
Dim sl As New sortedList()
For i As int32 = 0 To x.BranchCount - 1
For j As int32 = 0 To y.count
sl.add(x.Branch(i), y.item(j))
sl.IndexOfKey(x.Branch(i))
Next
Next
A = sl
What am I doing wrong?
----------------------------------------------------------------------------------
What I want to do is recreate the Closets Points component, but only need the index output. I am following this logic:
> ListPt.
> Distance between each point to ListPt. Returns a tree.
> Sort (Distance as key, indexes (0,1,2,3 ...) as values). Returns a tree.
>For i ... to Distance.branchCount -1
>> For j ... to N (number of points that I want)
>>> indicesTree.add (ValuesSorted.Branch(i).valuesSorted.item (j)). Returns a tree.
I'm on the right or is there a better way to get the CP index ?
Thanks :)
Tags:
There's a number of things I feel I should point out. In no particular order:
I'm somewhat confused about the problem though, you say you're looking for point indices, but your script works on numbers. In order to replicate the functionality of the Sort component, switch your inputs to List access, then use the following code:
Private Sub RunScript(ByVal x As List(Of Double), ByVal y As List(Of Integer), ByRef A As Object)
Dim arrX As Double() = x.ToArray()
Dim arrY As Int32() = y.ToArray()
Array.Sort(arrX, arrY)
A = arrY
End Sub
Good lesson, I am very grateful :)
Yes, I've had problems with SortedList () because it does not let me repeat the same value in the dictionary.
Now I'm having problems getting to use Array.Sort () in my branchs... To explain I try to do, here are some pictures: (It is very easy, but I'm having trouble encode...)
From the points of a mesh, find N-neighbors (but only interest me indexes).
I try to do as CP, but it would be better to do from the topology, I know how to get neighbors who share an edge, but take the neighbors of the neighbors up to N, I see too complicated for me.
I know there are functions in RhinoCommon of CP, but failed to use them :/
So, I'm trying to do the following:
But to make the array.Sort() in each branch, it does not return me the ordered indexes.
What am I doing wrong?
-CODE-
Private Sub RunScript(ByVal Mesh As Mesh, ByVal N As Integer, ByRef A As Object, ByRef B As Object, ByRef C As Object)
Dim NV As Integer = Mesh.Vertices.Count
'-----------------
'Indices vecinos
Dim ptM As New list (Of point3d) 'Puntos malla.
ptM.addRange(mesh.Vertices.ToPoint3dArray())
Dim dist As New datatree (Of Double) ' distancia entre puntos.
Dim ind As New list (Of Integer) ' Indices por puntos.
Dim indT as new datatree (of integer)
For i As int32 = 0 To NV - 1
For j As int32 = 0 To NV - 1
dist.add(ptM(i).DistanceTo(ptM(j)), New gh_path(i))
Next
ind.add(i)
Next
'Here below.
Dim arrY As Integer() = ind.ToArray()
For Each path As gh_path In dist.paths
Dim arrX As Double() = dist.branch(path).ToArray()
Array.Sort(arrX, arrY)
For j As int32 = 0 To N - 1
indT.add(arrY(j), New gh_path(path))
Next
C = arrX
Next
A = indT
B = ptM
End Sub
Thanks!
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