Grasshopper

algorithmic modeling for Rhino

I am playing with VB.NET coding tonight while following Grasshopper primer.  There is a code regarding generating a grid frustrated me. The code is on P106-p107.

I here attached my gh file for ur review. Please help me to figure out where is wrong.

Very appreciated.

here is the error message:
Error: Value of type 'RMA.OpenNURBS.On3dPoint' cannot be converted to '1-dimensional array of RMA.OpenNURBS.On3dPoint'. (line 98)

Error: Value of type '1-dimensional array of RMA.OpenNURBS.On3dPoint' cannot be converted to 'RMA.OpenNURBS.On3dPoint'. (line 99)

Views: 487

Attachments:

Replies to This Discussion


Dim pt As On3dPoint()


is wrong. If you add brackets after a Type, then that indicates the pt variable is an array.
Remove the brackets and your script will run.

Confusingly, if you add a New keyword, then the brackets mean something else:


Dim pt As New On3dPoint()


The New keyword indicates you are constructing a new point, which already has X, Y and Z coordinates. In this case, the brackets indicate that you are calling the empty constructor function. As opposed to:


Dim pt As New On3dPoint(x, y, z)


Which calls the constructor function that takes three numbers...

The fact that VB uses the same brackets for both function calls and arrays is one of my major annoyances. C based languages use square brackets for arrays, which isn't anywhere near as prone to confusion.

--
David Rutten
david@mcneel.com
London, UK
Hi, David:

Thanks for debugging my code and found out errors! I have a further q for this. Could you tell me how I can print the sequence number for the points? If I didn't explain my request well, pls see the attached image. The reason for asking this is I want to see how the following codes works in order if I put "cross reference" On component pt:

pt = Pts(j)
Row.Add(pt)

Also, is there any resource to help me to code vb.net for Rhino related issue? Will it help if I install Visual basic express 2010?

Finally, for the other codes, do I need to add anything in imports, members and other predefined libraries?
Attachments:
Hi cmrhm,

it's not easy to display text in the Rhino viewports. If possible you should use the TextTag or PointList components.

There is no data type in Grasshopper at present which can draw itself as text in the 3D display.

You can however use a scripting component to create a point-list and a string-list, then use those as inputs for a TextTag component.

--
David Rutten
david@mcneel.com
London, UK
Hi, David:

Thanks for pointing out point list and string list component. They works.
"The fact that VB uses the same brackets for both function calls and arrays is one of my major annoyances. C based languages use square brackets for arrays, which isn't anywhere near as prone to confusion."

So you like C more than VB? Personally I don't like VB that much although I am new to coding. It use '_' in naming so often. I feel C# is more friendly. But I know many user in GH is from Rhino Scripts group.

sad story for me. What is your opinions?
If you like C better, and C fits your style more, then go with it. After coding for a while, there really aren't all that many differences between C# and VB.Net other than general syntax stuff (which I assume isn't an issue if your more comfortable with C#). You really should be able to translate from one language to another without too much of an issue because of the close similarity. Even if you do run an example that you'd prefer in C#, there are online translators that can help you out. Ultimately, although one might prefer C# or VB.Net, you should really be able to understand, if not code in each language. But that's just me ;)
Thanks for your opinion. I agree with you they are similar in syntax.

No. I don't like C at all. C# is totally different with C, right? C# is more toward java.
C is totally different than C# if you're talking in the broader base of compilers, execution, etc. Sytnax wise, C# derives from C along with a long list of languages that Giulio mentioned before, so on that level they are similar.
If you ever scripted a webpage (Javascript), if you ever used Processing, ActionScript, Java or C and C++, you have already encountered the C language family and C# will be easier and look somehow familiar.
If you used vbScript or Visual Basic earlier, VB.Net will look friendlier.
Python looks different than both of the previous ones, but still resembles C and Java more than Vb.
So, really it's a matter of previous experience or future willingness to open to new languages. Personally, for some aspects I still like VB (I am thinking about optional parameters, that also Python has and appeared in C# 4.0), but lately I find C# more elegant and concise. Altogether, VB.Net and C# are really not too different.

- Giulio
______________
giulio@mcneel.com
Stockholm
The sad truth is that the better I know C#, the less I like it. An even sadder truth is that the better I know C# the less I like VB as well... Both languages have their own stupid (in my opinion) quircks. Some of these are inherent to the language syntax, others are mistakes in the respective development platforms. Here are my pet-hates for both languages:

C#
1) Case sensitive. Yes. C# is bloody case sensitive. That just makes it so much harder to use the intellisense properly, not to mention it is a bug factory. The only thing a case sensitive language allows you to do is declare functions and variables with the same name, but with different cases. I cannot imagine this is ever a useful thing.

2) Event syntax. Handling events is ok (though I still prefer the AddHandler, RemoveHandler approach of VB), but raising events is an f-ing nightmare in C#.

3) Curly brackets instead of keywords. Every source code file I have ends with a cascade of curly closing brackets. I much prefer the VB approach of End If, End Class, End Namespace. It's just so much clearer when I can see which end constructs means what.

4) It doesn't compile while I type, so any errors in syntax/logic only surface when I explicitly compile. This is annoying as it drastically increases the time I have to spend when fixing dozens/hundreds of compiler errors.

5) No optional parameters in function signatures.

6) Weird keywords like sealed, virtual, pure etc. I much prefer self-describing words like MustInherit NotInheritable, MustOverride etc.



VB
1) Parenthesis for both functions and arrays. Stupid stupid stupid stupid stupid.

2) The editor replaces my carefully crafter scientific notation to decimal notation. I type

Dim tol As Double = 1e-12

and it is replaced with

Dim tol as Double = 0.0000000000001

Someone please fire whoever thought this was a good idea.

3) Array indexing, declaration and looping. VB is consistent in that it always uses base-zero for array indexing. C# (and C and C++) mix zero-based and one-based syntax. So plus two points for consistency but minus 13 for making me write "-1" whenever I need to do something with arrays.

4) Can't remember what #4 was supposed to be, but there definitely was a #4... Anyway, when I think of it I'll append another post.


At this point in time I hardly prefer either language. I think on the whole they are both beautiful and the DotNET framework is a work of art (and pure genius). I use both languages extensively in my daily routine and I'm very happy with them.

--
David Rutten
david@mcneel.com
London, UK
It may just be me (and I am biased), but it sounds like your list is more leaning towards VB :)

C#
1) I think Coding Horror has ended up in a few of your posts, but I found this article pretty interesting... http://www.codinghorror.com/blog/2005/12/the-case-for-case-insensit...

2) Can we lump delegates into this?

VB
2) that seams like a Visual Studio thing than anything else... yet another reason to hate Microsoft. The odd thing about this is that it obviously knows what your doing, but changes it anyway.

3) why is -1 so bad?

Agreed on the DotNET framework. Its quite powerful and very well put together. For anyone who says that Micro$oft can't do anything right, somehow dotNET must have slipped through the cracks. Its by no means perfect, but it does what it does very well.
David, guilio:

Thanks for sharing your honest opinions. Those fxxx words enhance my understanding. I will digest them...

AS to my second q, could you give me some hints?
"
Thanks for debugging my code and found out errors! I have a further q for this. Could you tell me how I can print the sequence number for the points? If I didn't explain my request well, pls see the attached image. The reason for asking this is I want to see how the following codes works in order if I put "cross reference" On component pt:

pt = Pts(j)
Row.Add(pt)

Also, is there any resource to help me to code vb.net for Rhino related issue? Will it help if I install Visual basic express 2010?

Finally, for the other codes, do I need to add anything in imports, members and other predefined libraries?"

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service