Sequencing the Randomly 2D Drawing Entities Using DXF Format

The exchange of the data between the drawing programs like this one used in this research, AutoCAD, and the other application programs is very important to develop the applications in CAD systems. The present paper aims to make a logic sequence for the entities that are drawn randomly to prepare them to further CAD or CAM manipulations. The methodology in this work is using the DXF (Data Exchange File) which represents a CAD file format in which the drawing is saved by using AutoCAD package. All the required manipulations, begging from extraction the data of the drawing entities to accomplishment the sequencing, have been done by building a suitable visual basic program. Also, the AutoCAD package has been used as a checking tool for the results after applying the proposed program, by opening the new DXF file format to AutoCAD environment. The results show that the use of the concept of exchanging the data in CAD environment is a good way to apply the methodology of the research


INTRODUCTION
he computer aided design (CAD) is used for designing in various fields.The computer aided engineering (CAE) is not as popular as the CAD because the difficulty of preparing the CAE data.The CAD data is based on the outlines like lines, arcs, etc [1].Data Exchange File (DXF) format is one of the most popular file formats in CAD system.DXF files enable the interchange of drawings between AutoCAD and other application programs [2].
There are a lot of researchers had used the AutoCAD and DXF format in their works in different fields.Xiahou and et al [3] introduced an approach for auto-generating polyline using the data definition in DXF format and the method of auto-generation is obtained through the auto calculation of polyline bugle.Sukimin and Haron [2] used the DXF format to make feature extraction from the information of geometric entities.Many algorithms had built by Hussam and et al [4] using DXF format, AutoCAD, and visual basic programming for auto-generation di mensioning on 2D objects.In another work Hussam [5] introduced a new methodology to recognize the data of a 3D wireframe using DXF format.In the same way Baraa and et al [6] used the DXF to specify the location of datum points for rectangular symmetrical and nonsymmetrical dies.This point is useful for planning and is located automatically.More than JIANG [1] used the DXF format to create a two dimensional finite element analysis using CAD data which is generated from DXF.Also, some of the researches used AutoCAD with VBA where Fei Gao [7] had used VBA (Visual Basic Application) model of AutoCAD to make an automatic converting for the drawing from region to polyline.In his methodology, he used the ordering of the points and determined the starting points to apply his algorithm to realize the maps of walls.Chen and et al [8] used each of AutoCAD, visual basic for applications (VBA), and together with DXF format to build his software to transfer any 3D entity created by AutoCAD to simulation program.
In this paper, the use of AutoCAD, DXF, and together with programming language visual basic is adopted to make a procedure to sequence the entities drawn in random way starting from the initial drawing stage in AutoCAD passing the manipulations stage until seeing the final result in AutoCAD again.

DRAWING AND SEQUENCING ENTITIES Lines Algorithm
The line can draw in different directions from right to left or from down to up or vice versa or in oblique directions.The definition of the line in contends of the DXF file is fixed from the starting point in which the line is drawn.That means the line in the figure (1), which shows a simple two different directions for drawing a single line by two points, is drawn first from left to right where the starting point is "point1" in figure 1.a and when it is checked in DXF format it will be defined as "point1" is the first point and "point2" is the second point.In comparison the line2 in figure (1).b is defined in DXF format as "point1" at the first and "point2" is the second, but the direction of drawing is from right to left.This means, the drawing direction and data reading direction are the same.

Figure (1) a simple line in different direction.
The first step of the algorithm is to determine which point will be the starting point.This depends on the needed direction of drawing.This direction is either clockwise or counterclockwise, and the starting point will be the first point of the first line for the whole drawing.When there is another entity, for example line, connecting to the first one, the points of the second line should be examined such that the second point of the first entity is the first point of the second line to keep the sequence.The result of drawing set of entities is a certain shape, but the method of drawing from one to another is different.The modifying on any drawing leads also to create entities with random sequencing.The drawing shown in figure (3.a) is a simple shape that consists of seven segments which are drawn in random way.For some applications in CAD or CAM systems that need automatic manipulation, the logic sequence will be more meaningful to use.For example, if the application needs tool path generation for a milling operation, the Gcode program will logically start from certain point and move along the boundaries of the shape in sequence way.It is not logic the tool moves from point to point with not sequence, this is, the tool moves continuously.Therefore, figure (3.b) shows the logic sequencing of the drawing where the moving from point to another will be with which the way that keeps the continuously.

ARC ALGORITHM
There are many ways of drawing an ARC in AutoCAD but in fact the designer usually uses 2 or 3 of them.There are about 11 ways to draw an Arc namely: 3 points;  Length;and Continue [9].Also, the designer can logically draw the arcs in different directions.But even though there are all the ways used in AutoCAD to draw an arc, the procedure that is used to define an arc by DXF code is constant.There are four things used in this procedure to define any arc.These things are: the center of the arc, radius, starting angle, and ending angle with counter clockwise as shown in Figure ( 4) which represents two arcs that have been drawn in different direction but the definition in DXF format is the same.The algorithm proposed in this paper can deal with this information such that extraction the information of an arc will be found and converting start and end angles to start and end points are determined because the sequence approach needs points to be arranged as shown in figure 5. Calculating these points are given by the following formulas: … ( 1)

CONVERTING THE DRAWING
Sometimes the needing to convert the drawing from entities to one form or shape is important.That means the shape which consists of number of entities is represented by polyline to be used in some applications.When the sequence stage is complete, the algorithm of converting the sequenced entities to polyline will enter in work such that the points of the lines will be vertexes instead the points while the arc should need a certain modify.To convert the arc, the bulge should be determined.The bulge is the tangent of 1/4 of the included angle for the arc between the selected vertex and the next vertex.A negative bulge value indicates that the arc goes clockwise from the selected vertex to the next vertex as shown in Figure (6.A) bulge of 0 indicates a straight segment, and a bulge of 1 is a semicircle and the code 42 in the structure in the of DXF represent the bulge as shown in Appendix A. The formula to calculate the bulge is [3]: Where   is the angle between the starting and ending angle of the arc and it is calculated as (  -  )   ,   The designer can draw the required part in different ways depending on how the designer uses the capabilities of the drawing package.figure (7) shows an AutoCAD window involving a drawing consisting of many individual entities (lines and arcs) such that any modify on it will be as figures (8 and 9).Sometimes the designer wants to make a modification on parts of the drawing by applying the commands of modifying.Figure 8 shows a moving of line from one ends while figure (9) shows the moving of whole line from the center control points of the line.The same drawing in figure (7) has been converted to polyline and figure (10) shows the result of transferring to polyline.The drawing after converting to polyline and the modifying on the control point of the drawing will be as in figure (11).

CONCLUSIONS
The sequence of 2D drawing entities in this paper has been done successfully by executing the proposed program which is built using the programming language visual basic.The entities are drawn by AutoCAD package and the format of DXF that is considered as one of the famous formats of data exchanging is adopted for saving the drawing with (.dxf) extension.The program able to read all the contents of the DXFcode and extract all the necessary geometric information and addition to making the logic procedure to convert to polyline.The new code of the DXF file has been exported to AutoCAD to show the result.The sequence of drawing entities is important for some applications of CAD or CAD/CAM, for example, tool path generation.The structure of the DXF format is different when reading the drawing like lines and arcs than reading the drawing when it is a polyline.In polyline drawing, the geometric information will be vertexes and bulges.The polyline form can be used in making scaling and modifying for the drawing, also it can be generated 3D shapes from 2D polyline shape.
Figure (2) the lines before and after applying the algorithm.(a) and (b) before applying the algorithm.(c) and (d) after applying the algorithm.
Figure (3) Random and sequence segments of closed shape.
Figure (4) Two arcs in different directions with the same data reading direction.
Figure (5) Geometric information of the arc.
Figure (6) Direction of bulge drawing depending on the sign of bulge value.
Figure (7) Main Interface of AutoCAD application including many random individual entities.

Figure
Figure (9) Using center control point for modify shape entities.

Figure
Figure (11) the modifying the polyline by control point of the drawing.