A kind of method of one-touch extraction list data from autocad file
Technical field
The invention discloses a kind of method of one-touch extraction list data from autocad file, relate to computer graphics software
Technical field.
Background technology
AutoCAD is a current popular engineering drawing software.A lot of construction parties using AutoCAD software, in foundation
While drawing construction, it is also possible to carry out the buying of the goods and materials such as equipment, material according to the requirement of design and owner.To this end,
From autocad file, extract corresponding list data, and then data are saved as Microsoft Excel, be also that a kind of new client needs
Ask.
AutoCAD has been initially added into form (Table) object from R16, but due to aspects such as use habits, people are still
Get used to using by line (Line) and word (DBText) objects draw form.Each object in this form is from logic
There is no any contact on, be merely by respective position relationship and define a visual form effect.This form
With the difference that the part outside form does not has any essence.Accordingly, it is determined that the scope of form is the most difficult, and then table cannot be determined
The information such as the word in the line number of lattice, columns, cell.In order to determine the scope of form, the way of major part software is at present
Marked form scope by user hereof or choose the whole objects in form, then by determining the line number of form, columns, unit
The information such as the word in lattice.This way is the most feasible, but often operates the data that once can only extract a form.If form
Time many, complex operation, easy maloperation.
Summary of the invention
The technical problem to be solved is: for the defect of prior art, it is provided that a kind of one key from Auto cad file
Formula extracts the method for list data, can be with the whole list data of rapid extraction Auto cad file.
The present invention solves above-mentioned technical problem by the following technical solutions:
A kind of method of one-touch extraction list data from autocad file, concrete steps include,
Step one, from configuration file, obtain the feature of form, including text and the literary composition of rightmost end column gauge outfit of high order end list head
This arrangement, is DBText object 1 by the text definition of high order end list head, is DBText by the text definition of rightmost end column gauge outfit
Object 2, DBText object 1 and DBText object 2 forms a DBText object pair;
Step 2, set up the data structure of form;
Step 3, list data is filled up to the DataGridView control corresponding to initial data view;
Step 4, find corresponding gauge outfit DBText object according to the feature of list data, through calculating determine form scope,
The layout of cell, then determines the line order of the internal word of cell in the inside of cell according to the Y coordinate of DBText object;
Step 4, will through conversion list data be filled up to the DataGridView control corresponding to preview view;
Step 5, will through conversion list data export as EXCEL file.
As present invention further optimization scheme, described step 1 specifically includes,
In AUTOCAD file, collect object, set up DBText array, horizontal linear object array, vertical line object array;
Filter out whole DBText object 1 and DBText objects 2;
DBText object 1 and DBText object 2 is matched, forms a DBText object pair.
As present invention further optimization scheme, described step 2 specifically includes,
201, based on the position of DBText object 1 and DBText object 2, initial form scope is set up;
202, set up vertical line array and the X-coordinate array of form, find out the vertical line by form scope, often find one
Bar vertical line, is just added into vertical line array, and is comprise linear extent and form scope new by form expanded range
Scope, if it differs with the X-coordinate of other vertical line in form, just charges to X-coordinate array by the X-coordinate of straight line;
203, set up horizontal linear array and the Y coordinate array of form, find out the horizontal linear by form scope, often find one
Bar horizontal linear, is just added into horizontal linear array, and is comprise linear extent and form scope new by form expanded range
Scope, if it differs with the Y coordinate of other horizontal linears in form, just charges to Y coordinate array by the Y coordinate of straight line;
204, the position of whole cells of whole form is determined according to X-coordinate array and Y coordinate array, according to DBText pair
The position of elephant, charges to DBText object and Y coordinate thereof in the cell of correspondence.
Step 203 is also included as after present invention further optimization scheme, described step 203 ', to X-coordinate array
The data of data and Y coordinate array carry out anti-interference process, are ranked up the data of coordinate array, check coordinate and upper one by one
The difference of one coordinate, if difference is less than the threshold value set, just deletes this coordinate from array.Wherein, described thresholding
Value is 1 millimeter.
The present invention uses above technical scheme compared with prior art, has following technical effect that the method disclosed in the present can
With the list data that rapid extraction autocad file is whole.Data in form can be saved as Microsoft Excel, enters
The utilization of one step.The operation of whole process is the most convenient.
Accompanying drawing explanation
Fig. 1 is the structural representation of form related data.
Fig. 2 is the schematic flow sheet of the method for the invention.
Detailed description of the invention
Embodiments of the present invention are described below in detail, and the example of described embodiment is shown in the drawings, the most extremely
Same or similar label represents same or similar element or has the element of same or like function eventually.Below by ginseng
The embodiment examining accompanying drawing description is exemplary, is only used for explaining the present invention, and is not construed as limiting the claims.
Below in conjunction with the accompanying drawings technical scheme is described in further detail:
With the actual mechanical process of user as embodiment, after user clicks on derivation form button, through program analysis and
Calculate from AUTOCAD file, identify some forms, and show in form derives forms.Derive the forms of form by 4
Part composition.Top line be drawn into list data after selectable operation.List data can be exported to by user
In Excel.Second row is the positional information of the form extracted.The cell of the different rows that Clicks here will show in fourth line
Different forms.The third line is the view pattern that form is different.User want to see can select with the form that escape dictionary is converted " pre-
Look at " view.User wants that the initial data seeing AUTOCAD can see initial data view.User can also select " contrast " to make
Obtain two kinds of views to show simultaneously.
In a particular embodiment, the table features in the user interface of table features is set and refers to the text of high order end list head and the rightest
The arrangement of the text of end list head.It is assumed that the text of high order end list head is " sequence number " in a form, rightmost end column gauge outfit
Text be " remarks ", then the feature of this form is exactly the arrangement of " sequence number " " remarks ".Hereafter be based on assumed above enter
Row introduces the processing procedure of program.
Because the content of the DBText object of AUTOCAD possibly cannot be directly displayed in the control of Windows.So needing to set
Put the user interface of form word escape, carry out escape process.
As in figure 2 it is shown, the process extracting list data comprises the steps of
One, from configuration file, obtain the feature of form.Including:
In AUTOCAD file, collect object, set up DBText array, horizontal linear object array, vertical line object array.
Filter out the DBText object of whole sequence number and remarks.
Sequence number DBText object and remarks DBText object are matched.
Two, the data structure of form is set up.Including:
Initial form scope is set up based on the position (Position) of sequence number DBText object and remarks DBText object
(Extents3d)。
Set up vertical line array and the X-coordinate array of form.Find out the vertical line by form scope.One is often found to hang down
Straight straight line, is just added into vertical line array, and is to comprise linear extent and the new range of form scope by form expanded range.
If it differs with the X-coordinate of other vertical line in form, just the X-coordinate of straight line is charged to X-coordinate array.
Set up horizontal linear array and the Y coordinate array of form.Find out the horizontal linear by form scope.Often find Yi Tiaoshui
Flat line, is just added into horizontal linear array, is just to comprise linear extent and the new range of form scope by form expanded range.
If it differs with the Y coordinate of other horizontal linears in form, just the Y coordinate of straight line is charged to Y coordinate array.
The data of X-coordinate array and the data of Y coordinate array are carried out anti-interference process.The data of coordinate array are ranked up.
Check coordinate and the difference of a upper coordinate one by one, if difference is less than thresholding (assuming it is 1 millimeter), just by this coordinate from array
Middle deletion.
The position of whole cells of whole form is may determine that according to X-coordinate array and Y coordinate array.According to DBText object
Position, DBText and Y coordinate thereof are charged to correspondence cell in.
Three, form extracts process is that the feature according to form finds corresponding gauge outfit DBText pair, as it is shown in figure 1, through calculating
Progressively determine the layout of the scope of form, cell.In the inside of cell then determines cell according to the Y coordinate of DBText
The line order of portion's word.
Four, list data is filled up to the DataGridView control corresponding to initial data view, will fill out through the data of conversion
Write the DataGridView control corresponding to preview view.
Five, user is optional is submitted to list data other system or exports as EXCEL file.
Above in conjunction with accompanying drawing, embodiments of the present invention are explained in detail, but the present invention are not limited to above-mentioned embodiment,
In the ken that those of ordinary skill in the art are possessed, it is also possible to make various on the premise of without departing from present inventive concept
Change.The above, be only presently preferred embodiments of the present invention, and the present invention not makees any pro forma restriction, although
The present invention is disclosed above with preferred embodiment, but is not limited to the present invention, any those skilled in the art,
In the range of without departing from technical solution of the present invention, when the technology contents of available the disclosure above makes a little change or is modified to equivalent
The Equivalent embodiments of change, as long as being without departing from technical solution of the present invention content, according to the technical spirit of the present invention, in the present invention
Spirit and principle within, any simple amendment that above example is made, equivalent and improvement etc., all still fall within this
Within the protection domain of inventive technique scheme.