algorithmic modeling for Rhino
good evening,
I've encountered a confusing error, which I am unable to fight on my own. I'd appreciate your help.
I have two inputs of DataTree:
y is composed of 2-level DataTree, 3 branches and under each one you find a bunch of different items (curves).
x contains more complicated structure (DataTree), only by one level though. So I got again 3 branches, each has a couple of sub-branches and then on each sub-branch there are two items (points).
What I wanted to do is to find a closest point from both points on each sub-branch to every curve on the same branch.
Private Sub RunScript(ByVal x As DataTree(Of Point3d), ByVal y As DataTree(Of Curve), ByVal prm As Object, ByVal ttl As Object, ByRef A As Object)
Dim j,i,e As New Integer
For i = 0 To y.BranchCount - 1
For e = 0 To x.BranchCount - 1
Dim pth As New GH_Path(i, e)
Dim pth1 As New GH_Path(i, e)
Dim pt As Point3d = x.Item(pth, 0)
Dim pt1 As Point3d = x.Item(pth, 1)
For j = 0 To y.Branch(i).Count - 1
Dim t,t1,dist As New Double
y.Branch(i).item(j).ClosestPoint(pt, t)
y.Branch(i).item(j).ClosestPoint(pt1, t1)
dist = pt.distanceTo(y.Branch(i).item(j).PointAt(t))
dist += pt.distanceTo(y.Branch(i).item(j).PointAt(t1))
'code would continue here with a "if-statement"
Next
Next
Next
End Sub
When I run this, I get an error: The given key was not present in the dictionary.
It all started with an addition of x.Item(pth,0). I struggled addressing the actual items at the end of my DataTree. I usually handle only two levels, so I get by with Branch(i).item(j)..
Any ideas? It's probably something trivial.
Tags:
You're asking the datatree "x" looking for a branch that does not have: {i, e}.
I can not help you because I am not clear your explanation. (pictures please! skfhskdfh:P)
But perhaps (perhaps) the problem is thinking path branches as if they were separate branches. That is not like that. I mean, the branch {0, 2, 4} is a lane, not three lanes. Therefore, if you have tree, something like {0, 1, 3}, {0, 1, 4}, {0, 1, 5}... and want to iterate over the elements of the branches:
For i as int32 = 0 to tree.BrachCount -1
For j as int32 = 0 to tree(i).Count -1
(...)
'item = tree(i)(j)
next
next
What you have to do is match the routes of the branches to operate between inputs.
thanks for your reply
I forgot to send the picture.
Additionally, I've uploaded a sample script, that contains similar data I work with.
it does not make sense to me - there has to be this particular {i,e}..
Welcome to
Grasshopper
© 2025 Created by Scott Davidson.
Powered by