![]() This part interprets the drawing objects found in the DXF file. MessageBox.Show( " An error occurred while opening the DXF file") MessageBox.Show(e.FileName.ToString() + " cannot be found") Reader = theSourceFile.OpenText() // the reader is set. StreamReader reader = null // a reader is prepared. TheSourceFile = new FileInfo (textFile) // the source file is set. Line1 = " 0" // line1 and line2 are initialized here. String line1, line2 // these line1 and line2 is used for getting the a/m data groups. Public void ReadFromFile ( string textFile) // Reads a text file // (in fact a DXF file) for importing an // Autocad drawing. In addition to the standard namespaces, the following namespaces are included: NewCanvas.Show() // the canvas is displayed.Īs mentioned above, DXF interpretation is made in the Canvas class. NewCanvas.ReadFromFile(inputFileTxt) // the filename is sent to the method // for data extraction and interpretation. NewCanvas.MinimumSize = new Size ( 500, 400) //. ![]() filename is // extracted from the text.(blabla.dxf). (ino+1, inputFileTxt.Length - ino - 1) //. NewCanvas = new Canvas() // a new canvas is created. of the last "\" // (that is before the filename) // is found here InputFileTxt = openFileDialog1.FileName // filename is taken // (file path is also included to this // name example: c:\windows\system\blabla.dxf int ino = inputFileTxt.LastIndexOf( " \\ ") // index no. if "cancel" button is clicked then // nothing will be done. OpenFileDialog1.Filter = " DXF files (*.dxf)|*.dxf|All files (*.*)|*.*" // filters the // visible files. OpenFileDialog1.InitialDirectory = " c:\\ " // sets the initial directory of the // openfile dialog Private void menuItem2_Click( object sender, System.EventArgs e) // Opens openfile // dialog to select a DXF file When you click File/Open, the following method will be called: Separating these methods from the drawing methods would be much better but for now this is all I can present. In the near future, I'm planning to add B-Spline too.ĭXF Interpretation methods are included in the canvas class. Currently Line, Polyline, Circle and Arc shapes of the AutoCAD can be recognized. There is a Canvas class for drawing and a Shape class for defining objects. You can open multiple DXF files for viewing. The data is extracted from the DXF file and interpreted and then necessary methods of the viewer are called and the result is shown on the screen.Īlthough the intended structure is as above, the code itself is not separated this much. Well, as you can see, the structure is as above. (I'll try to provide details later on.) General Structure DXF File However, the only interaction that the editor presents to the user is to highlight the shapes (to highlight keep shift button pressed while moving the cursor). And the project become partially a DXF reader and mainly a viewer program, and I also made a drawing editor. But then I found out that a reader by itself will have no value, there should also be a viewer. After various scans through the net, I came across the DXF specification of the AutoCAD and I decided to make my own reader. There are a couple of DXF writer projects here in CodeProject (one is from Omid Shahabi, the other is from Claude Gagnon), but I couldn't find a DXF reader which reads DXF files. In fact, at the beginning my sole purpose was to extract data from a DXF file but later on interpretation and drawing of the data on the screen started to take much more time and shaded the priority of the data extraction. This project mainly deals with reading a DXF file, but in order to demonstrate the reader is working I also included a viewer, which interprets the data and draw it on the screen.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |