0

I'm writing a C# code to extract data from a AutoCad drawing. I managed to display all the data from the drawing in the RichtextBox but I only wanted the X, Y coordinations (start and end points) of the wires, how should I write the code?

// DWGFilePath is the file selected from OpenFileDialog 
var FileStream = new FileStream(
  DWGFilePath, 
  FileMode.Open, 
  FileAccess.Read, 
  FileShare.ReadWrite); 

var file = new StreamReader(FileStream, System.Text.Encoding.UTF8, true, 512);

FinalContent = file.ReadToEnd();

richTextBox1.Text = FinalContent;
Dmitry Bychenko
  • 180,369
  • 20
  • 160
  • 215
  • What are the data you've read? What is the format of the file, is it dwg (https://en.wikipedia.org/wiki/.dwg)? – Dmitry Bychenko Jul 03 '19 at 07:39
  • @DmitryBychenko yes it is, he write it as variable name and comment. – Mar Tin Jul 03 '19 at 07:41
  • https://stackoverflow.com/questions/169390/open-source-cad-drawing-dwg-library-in-c-sharp https://nugetmusthaves.com/Tag/autocad – Dmitry Bychenko Jul 03 '19 at 08:00
  • @DmitryBychenko The data i've retrieved are words and integers, all arranged line by line, part of them is shown below: VERTEX 5 2721 330 271E 100 AcDbEntity 8 L33D0_WIRE 100 AcDbVertex 100 AcDb2dVertex 10 **8433.45** 20 **7463.775** 70 0 0 SEQEND The data i need are the bold ones. i'm thinking if there is a method i can detect the wire from the autocad drawing so i could just retrieve the coordinates. – Peace Gusta Jul 04 '19 at 01:48
  • @Peace Gusta The native format of AutoCad is .dwg and .dxf where .dwg is binary so I suppose can't be read as text. So the code in comment suggest that You have dxf file. in the code for example here: https://stackoverflow.com/questions/1000785/reading-dxf-files You will find more info and sample how to manage DXF files – CAD Developer Jul 04 '19 at 05:59
  • Why you parse a file instead let acad do the job (load the drawing) and ask ACAD via Cä later on to deliver the coordinates ? There is a fine database wher you can ask whatever. – Thomas Ludewig Jul 07 '21 at 14:50

0 Answers0