Grasshopper

algorithmic modeling for Rhino

Hi,

I´d like to know how the parser in file works. Is it like a vb.net script? Can I code in c#?

Any examples?

Thanx

Views: 895

Replies to This Discussion

Yes, VB only. You essentially parse the String you're given and return an object which represents the string. Let's assume you have a textfile which contains the following:

0; 0.5; 0.5; 0.5
1; 0.8; 0.2; 0.0
2; 2.5; 0.0; 1.0

The first number is merely the index and the last three numbers on each line represent the x, y and z coordinates of a point. We cannot use the in-build String->Point converter in Grasshopper because it doesn't understand that a point coordinate might consist of 4 parts, the first one of which is an index.

So, you write the following parser, and you're done:

Dim parts As String() = data.Split(";".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)

Dim x As Double = Double.Parse(parts(1))
Dim y As Double = Double.Parse(parts(2))
Dim z As Double = Double.Parse(parts(3))

Return New On3dPoint(x, y, z)

--
David Rutten
david@mcneel.com
Poprad, Slovakia
Thanks for your help
I tryed to use david's code but It gave some strange errors.
Namespace problems.
I post all in this discussion

http://www.grasshopper3d.com/forum/topics/write-a-parser-for-obj-fi...

explanations and suggestions are welcome
Paolo,

I totally forgot to fix that code when I switched to the new SDK in Grasshopper 0.7
I'll have to do so soon, but in all likelyhood any existing parser code will become unusable.

--
David Rutten
david@mcneel.com
Turku, Finland
Hi Paolo,

how about using a normal C#/Vb.Net scripting component? Once one is used to it, I find it is much friendlier and reliable than the parser... plus, it will keep on working from 0.6 -> 0.7.

I've attached a small example, in the hope it could be somehow useful.

- Giulio
________________
giulio@mcneel.com
McNeel Europe, Barcelona
Attachments:
Thanks David and Giulio
Yeah I already wrote my Vb component to parse the file.
but I was still curious to understand how the parser works.
example very useful...

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service