70001366 Exporting x y z coordinates in txt file

Article 70001366
Type HowTo
Product Engine
Version 7
Date Added 7/12/2018
Fixed 7 (7/12/2018)
Submitted by John Sheedy

Summary

How can I export the x,y,z data of the lines and polylines in a drawing into a txt file?

Solution

VDF doesn’t have this capability automated but it is very easy to export this txt file from any drawing loaded into the VDF component. See this code below:

private void button1_Click(object sender, EventArgs e)
{
    vdDocument doc = vdFramedControl.BaseControl.ActiveDocument;
    doc.New();
    doc.Open(@"c:\test\MyModel Layout_1.0.dxf"); 

    using (StreamWriter writer = new StreamWriter(doc.FileName+".txt")) //export c:\test\MyModel Layout_1.0.dxf.txt file containing the points of lines and polylines only
    {
        foreach (vdFigure item in doc.Model.Entities)
        {
            if (item != null && item is vdLine)
            {
                writer.WriteLine("vdLine " + (item as vdLine).StartPoint.ToString() + " " + (item as vdLine).EndPoint.ToString());
            }
            if (item != null && item is vdPolyline)
            {
                writer.Write("vdPolyline ");
                foreach (Vertex item2 in (item as vdPolyline).VertexList)
                {
                    writer.Write(item2.AsgPoint().ToString() + " ");
                }
                writer.WriteLine(" ");
            }
        }
    }
}
All you need is to cycle in a loop through all objects (lines, polyline etc) in the document and get their x,y,z values and write them in a txt file with StreamWriter.

Send comments on this topic.