Write To CSV C#

I want to add to this existing component a way to input a Delimiter (separator).
I can change it manualy in C# and it works, but I want to be able to input it.

Write_csv1.gh (10.7 KB)

You want to input the char, or the index?

Either way add an input to your script, either with hint string or int, and add a readonly class level variable to your class which is set from the constructor.

Or you could add a get/set property if you’re not worried about some thread changing it while the class is busy writing data to a file.

1 Like

Tried to do it but I just can’t manage to make the script work. I have tried with a string hint. But then I just can’t figure out how to either change the char or the index… Anything I have tried just crashes. My programing skills are… Well… laughable really…

Hello, Have you tried with Python?

Most people find it much more friendly

Nope. I CAN’T code in all the languages out there :smiley:
But in this particular script all that I am trying to achieve is input a character somehow…
I thought it will be simple enough so even I can do it.

Quite easy, I just had to understand the classes.
Write_csv1.gh (9.0 KB)
The delimiter is one caracter string
As there is no method for writing a file and it is just in the constructor I added an argument in the constructor. A char here, it could be an int if you want …
The class CsvFileWriter is derived from CsvFileCommon

2 Likes

Is this all that was needed?

So I have to write the input into the public part, then the Delimiter obtainst the arg_delimiter value.

So the char arg_ part converts the string to char?
What does the “this.” in front of Delimiter do?
And lastly… Why do I do this in this part of the script? I get that we just ignore and bypass the previous value for Delimiter, but why exactly at this point?

In any case, thanks :slight_smile: Like for a 100-th time these few days :slight_smile:

Hmm… it seems to be equivalent to self in Python.

You use a class by creating an instance of that class. That code is saying that this instance of the class will have a parameter delimiter equal to the given argument

1 Like

This is not mandatoy, it was just more useful for me to discover what method, data has the class. You can suppress “this.”. But try use it to discover the class, there is auto completion with that.
The conversion string to char is here

The delimiter is inhirited by CsvFileWriter from CsvFileCommon.
As you write in a file using a constructor. You can’t modify the variable before the constructor. So I have to do it during the construction of the class.

A better approach could be to add a method in CsvFileWriter to write file and to have constructor empty.
You must learn Object Oriented Programming. It is very powerful.

1 Like

You have no idea how many gray hairs I have grown to find where and how to do the conversion to Char :smiley:

Use google !!

1 Like

I did! Now when I see how you did it I get the logic. I plan to spend some time learning the syntax and then do a buch of tutorials by gradually increasing the difficulty.

Do you recomend starting with C#? Which one of the language options do you think is a good start?

C# is good. I prefer C# because it allows me to write dll in visual studio, I had some experience in C++, it is quite strict (I prefer). Many script are available in C#. In your domain @PeterFotiadis seems to use it a lot. He will be happy if you convert you :angel:to C# :stuck_out_tongue:


I am sure there are lots of arguments for Python

1 Like

Oh I know him he is crazy good coder :slight_smile:

3 Likes

I chose Python because it is widely used in engineering and science, and because it is integrated in Rhino and Paraview, both of which I use.

The main advantages are :

  • shallow learning curve (get started quickly)
  • large standard library and open source plugin repository (no need to reinvent the wheel)
  • long learning curve (you don’t find yourself limited after a few years, like with Basic)
  • good for web development
  • good for science and engineering
  • allows rapid development and iteration
  • welcoming community (like Rhino :slight_smile: )
  • easy integration with C family languages
1 Like

So you can’t do Iterations with C#?

For sure Python has also many advantages. In my job with limited right to execute software, Python is a good alternative as it doesn’t need to be installed, just copied somewhere.

Happyt to see a Paraview user. I used it long time ago. And before AVS Express (a sort of Grasshopper 25 years ago)
For @davidsmavrov, choose one language C# or Python, don’t hesitate.

2 Likes

Eventually I will eat them both. But one after another.