Grasshopper

algorithmic modeling for Rhino

Hi all,

I recently updated to V0.8.0004. Since updating from the previous version I am having trouble with some very simple code that was working perfectly. I have simplified this down even further to this:
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

I then get this error:
Error: Overload resolution failed because no accessible 'New' is most specific for these arguments: (line 90)

If I rewrite (and change the access to Items NOT List) to:
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

..then it works pefectly!

Is there a bug with accessing list items? Or have I been staring at the screen for too long and I'm missing something very obvious?!

Thanks,
Toby

Views: 1287

Replies to This Discussion

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

Thanks David !

I have tried the script but get an error unfortunately...

Cheers,

 

Arthur

Attachments:

Missing bracket at red squiggly line. I'll fix it in my post.

 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Thanks David,

Still having an error :(

Getting rid of the problematic "new" gives:

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
Attachments:

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

Thanks all your help. Strange that VB was getting confused between points and vectors only when you fed it a list (but items were fine). When I am back in the office I will have to make the choice whether to stay in 0.8.003 or rewrite all my VB components!

Thanks again,
Toby

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service