Draw a polygon by csv-file

Hi all, I’m an absolute beginner in dynamo, and hope to find here a little help.
I would like to draw a polygon with coordinates from a text-file.
The coordinates have only x and y values (decimal values and comma separated).

Importing the file gives me two lists though. And the decimal point disappears.


Any help appreciatetd.

Hi,
for your import problem you can try with Division node, dividing everything by 1000. Otherwise you can try with Excel to see if it recognizes the decimals.

Moreover you need to create points to feed in your Polygon.ByPoints node (that’s why is yellow, you are connecting numbers instead of points). You can simply use Point.ByCoordinates, taking input X and Y from your list of imported coordinates.

1 Like

Instead of importing the CSV, use a File.ReadText node. You’ll have to parse the data out with some strings nodes but that’s a good learning exercise.

String.Split with a split string value of a string node containing only a new line character in it. Then String.Split with a , as your separating value. After that you’ll have to convert the strings to numbers.

From there you should be on your way.

2 Likes

Thank you Luca and Jacob very much!
Your advices were very helpful for me, I made some progress :smile:

I could convert the text-file into a number list. But it’s nested. Is that a problem?
And there is still a problem, with the drawing-part:

You need to Transpose your list so you have X values in one list and Y values in the other. Then you will need a First Item and a Last Item node to pull the X values and Y values out of the list. After that you will want to make a Point By Coordinates, making sure you choose a method with only X and Y values. Then you will want to make a Polycurve By Points to complete the effort.

After all of that, go do the Dynamo Primer in its entirety. Skip nothing, even if you think you’ll never use it. The excercises are designed to teach concepts, not outcomes. While you may not have to place solar panels on a roof, you’ll have to utilize cross product lacing often.

-jacob

1 Like

finally it works - thank you very much!
this is, how it looks like:

2 Likes

Does anyone know why String.Split produces a different out with the “;” in a Code block?

Maybe it is a special character? Try “\;”

Edit: Trying that throws up an error. Must just be an issue with ;

1 Like