This project has moved and is read-only. For the latest updates, please go here.

Reading multiple polylines into vertices

Aug 10 at 10:06 PM
First of all, I'm new to programming. I'm trying to read the vertices from multiple polylines. My program works for reading one polyline but crashes when I have multiple polyline in a dxf file. I think the solution is easy but can't figure it out. Any help is appreciated.

using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using netDxf;
using netDxf.Blocks;
using netDxf.Entities;
using netDxf.Header;
using netDxf.Tables;

namespace polyline_read_test
public partial class Form1 : Form
    List<inform> Information = new List<inform>();
    public Form1()

    private void button1_Click(object sender, EventArgs e)
        List<double> x1 = new List<double>();
        List<double> y1 = new List<double>();
        List<double> z1 = new List<double>();
        int count = 0;

        if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK) 
            DxfDocument dxfLoad = DxfDocument.Load(openFileDialog1.FileName);

           foreach (Polyline polyline in dxfLoad.Polylines)          // I think this is the problem!!!!

                // count = count +1;
                textBox1.Text = count.ToString();
                foreach (PolylineVertex vertex in polyline.Vertexes)
                   // textBox1.AppendText(string.Format("{0} xxx", vertex.Position.X));


            for (int i=0;i<= (x1.Count-1);++i)
                inform newinfo = new inform();  // This has to be  inside the loop or you get last x,y,z on the loop

                newinfo.x = x1[i];
                newinfo.y = y1[i];
                newinfo.z = z1[i];


            dataGridView1.DataSource = Information;

    public class inform
        public double x { get; set; }
        public double y { get; set; }
        public double z { get; set; }
Aug 16 at 5:02 PM
I do not see any problem in the code you are showing. I see that you are reading all 3d polylines in the file, and putting all the coordinates of their vertexes in one place (Information list), and its working fine if that is your intention. You could do the same thing in a single loop, but this is a different story.

What is the error message you are getting? In which line the execution is stopping?