algorithmic modeling for Rhino
Private Sub RunScript(ByVal pt1 As List(Of Point3d), ByVal pt2 As List(Of Point3d), ByRef A As Object)
Dim myLine As New Line
Dim arrLines As New List (Of Line)
For i As Integer = 0 To pt1.Count - 1
myLine = New Line (pt1(i), pt2(i))
arrLines.Add(myLine)
Next
A = arrLines
End Sub
Error: Overload resolution failed because no accessible 'New' is most specific for these arguments: (line 90)
Private Sub RunScript(ByVal pt1 As Point3d, ByVal pt2 As Point3d, ByRef A As Object)
Dim myLine As New Line
myLine = New Line (pt1, pt2)
A = myLine
End Sub
Tags:
Hi Toby,
I don't see a gaping error either right away. Well, I do, but since you claim your second script works that's obviously not it.
Rhino.Geometry.Line is a 'structure' in RhinoCommon, sometimes called a 'Value Type'. We did not have these in the old SDK, we were only using classes ('Reference Types').
A Value Type works just like an Integer. When you declare one, it gets a default value of zero. There's no way to have an Integer variable without some integer value assigned to it.
You don't therefore need to 'instantiate' Line as you used to do with OnLine.
You can rewrite your code like this:
If (pt1 Is Nothing) Then Return
If (pt2 Is Nothing) Then Return
If (pt1.Count <> pt2.Count) Then
Print("pt1 and pt2 need to have the same number of points")
Return
End If
Dim lines As New List(Of Line)(pt1.Count)
For i As Integer = 0 To pt1.Count - 1
lines.Add(New Line(pt1(i), pt2(i)))
Next
A = lines
I suspect the problem is that there is no constructor for Line that takes zero arguments. Thus:
Dim myLine As New Line
is not valid code. Just leave out the 'New' and you should get a default line (from 0,0,0 to 0,0,0)
--
David Rutten
david@mcneel.com
Poprad, Slovakia
Missing bracket at red squiggly line. I'll fix it in my post.
--
David Rutten
david@mcneel.com
Poprad, Slovakia
Darnit, there is a bug in RhinoCommon. It is causing confusion between two Line constructors when Option Strict is Off.
There's no solution, you cannot use this constructor at present. You'll have to say:
Dim ln As Line
ln.From = pt1(i)
ln.To = pt2(i)
I'll see what it would take to get it fixed.
--
David Rutten
david@mcneel.com
Poprad, Slovakia
It seems that this was introduced after this post.
This is the explanation. The following code works, because it states explicitly the variable type. Without this, it seems Vb (strangely) thinks that pt1(i) might be a Vector3d as well.
If (pt1 Is Nothing) Then Return
If (pt2 Is Nothing) Then Return
If (pt1.Count <> pt2.Count) Then
Print("pt1 and pt2 need to have the same number of points")
Return
End If
Dim lines As New List(Of Line)(pt1.Count)
For i As Integer = 0 To pt1.Count - 1
Dim pt1i As Point3d = pt1(i) 'Explicit variable type
Dim pt2i As Point3d = pt2(i) 'here as well
lines.Add(New Line(pt1i, pt2i))
Next
A = lines
This is very weird indeed. I never would have guessed this could be a problem. Taking out the casting operators for Vector3d and Point3d solves the problem. Using Narrowing casting operators solves the problem. Using 'Option Strict On' does not solve the problem.
No matter what I do, the change will break some existing scripts.
--
David Rutten
david@mcneel.com
Poprad, Slovakia
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