Grasshopper

algorithmic modeling for Rhino

Why are some classes originally defined in the Rhino SDK as classes now defined as structures in RhinoCommon? For instance a vector and a plane are now each defined as a structure. This means I cannot use a vector or a plane as an optional parameter to any of my functions, structures are not allowed for optional parameters. Why not keep them as a class? What is the benefit of changing them now to structures?

 

Views: 517

Replies to This Discussion

I believe they are more memory efficient as structs as they are not required to be loaded on the heap for function calls. I think another benefit is that when possible they are now kept within managed code in dotNET, rather than crossing into unmanaged c++ classes they derive from.

Does vb.NET prevent them as optional parameters (I typically code in c# that doesn't allow optional parameters so you can only overload functions)? You can still use them as optional "values", for my code I was previously testing variables to see if they were null. Instead you will need to test the isValid property (or if it's equal to Unset) and instead of null, use the Unset property such as
Point3d p = Point3d.Unset
Thanks Jon.

Yeah, VB.NET does not allow structures to be optional parameters in the argument of a function or sub. See here

http://msdn.microsoft.com/en-us/library/k56hxctb(v=VS.90).aspx

yes, the only way round it is to specify the structure parameter as required or replicate teh optional parameters by creating multiple signatures to the sub or function for overloading, but this is inefficient in havng to create multiple lines of code for each function, isntead of just using optional parameters for one function.
Hi,

in Vb.Net 10 (Visual Studio 2010) you can. You are able to use nullable value types for this.

Private Function DoSomething(Optional ByVal int As Integer? = Nothing) As String

If int Is Nothing Then
Return "Nothing"
End If

Return int.Value.ToString()

End Function
Giulio,
is VS 2010 working for you for grasshopper/rhino. i remember a few months back vs2010 did not play nice with grasshopper so i have been using 08. can i now use it?
Hi Robert,
here is what I know:

if you use Rhino 4.0 - please do no update to VS 2010, because it uses the Framework version 4.0, which means you will probably not be able to debug.

If you use Rhino 5.0 - then you should be able to use Visual Studio 2010 provided that you do not link to RhinoDotNET.dll (the old SDK), or you use one of the Express editions. As far as I know, the Express editions installed independently do not show the "indirect dependency on the .NET Framework assembly mscorlib, Version=4.0.0.0" compilation error. I think that Steve was investigating this error, but it seems an internal issue of Visual Studio.
I have been also able to debug (hit breakpoints) in VS 2010 with no link to RhinoDotNET.dll.

- Giulio
_________________
giulio@mncneel.com
McNeel Europe, Barcelona
I could be wrong but you could always pass integers as optionals. I have been doing that along with classes. The problem is structure type optional parameters cannot be used. Have you checked to see if you can pass structure types as optional? For instance the point3d or vector structure in 0.7?
Hi,

with Integer, yes, it was already possible. But the use with nullable integers is new. In the method signature, see "Integer?" instead of "Integer".
Integer? is a structure and is just actually a language equivalent of Nullable(Of Integer).

So you can write "Is Nothing" even if that is a structure.
Therefore, yes, with Point3d? it will be valid. Note again the "?". This allows the extra Nothing value. Without it, Nothing would just be the same as Point3d(0,0,0)

Function Name(Optional ByVal int As Point3d? = Nothing) As String

If int Is Nothing Then
Return "The is no point"
End If

Return int.Value.ToString()
End Function


This is tested to work in Visual Basic Express 2010.

- Giulio
_________________
giulio@mncneel.com
McNeel Europe, Barcelona

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service