⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dxf.htm

📁 刚刚看到本站有Visual C++数字图象处理(人民邮电出版社)的电子书
💻 HTM
📖 第 1 页 / 共 5 页
字号:
     nates in the dxf file.  you'll have to know the method by which

     autocad calculates the x and y axes in order to work with these

     values.

  o  the elevation value stored with an entity and output in dxf files

     will be a sum of the z coordinate difference between the ucs xy

     plane and the ecs xy plane, and the elevation value that the user

     specified at the time the entity was drawn.

</pre>

    <pre>arbitrary axis algorithm</pre>

    <pre>the arbitrary axis algorithm is used by autocad internally to implement the

&quot;arbitrary but consistent&quot; generation of entity coordinate systems for all

entities except lines, points, 3d faces, and 3d polylines, which contain

points in world coordinates.</pre>

    <pre>given a unit-length vector to be used as the z axis of a coordinate system,

the arbitrary axis algorithm generates a corresponding x axis for the coor-

dinate system.  the y axis follows by application of the right hand rule.</pre>

    <pre>the method is to examine the given z axis (also called the normal vector)

and see if it is close to the positive or negative world z axis.  if it is,

cross the world y axis with the given z axis to arrive at the arbitrary x

axis.  if not, cross the world z axis with the given z axis to arrive at

the arbitrary x axis.  the boundary at which the decision is made was

chosen to be both inexpensive to calculate and completely portable across

machines.  this is achieved by having a sort of &quot;square&quot; polar cap, the

bounds of which is 1/64, which is precisely specifiable in 6 decimal frac-

tion digits and in 6 binary fraction bits.</pre>

    <pre>in mathematical terms, the algorithm does the following (all &quot;vectors&quot; are

assumed to be in 3d space, specified in the world coordinate system).</pre>

    <pre>    let the given normal vector be called n.

    let the world y axis be called wy, which is always (0,1,0).

    let the world z axis be called wz, which is always (0,0,1).</pre>

    <pre>                                                                         19

&#12;autocad reference manual</pre>

    <pre>we are looking for the arbitrary x and y axes to go with the normal n.

they'll be called ax and ay.  n could also be called az (the arbitrary z

axis).</pre>

    <pre>    if (nx &lt; 1/64) and (ny &lt; 1/64) then

       ax = wy * n      (where &quot;*&quot; is the cross-product operator).

    otherwise,

       ax = wz * n.

    scale ax to unit length.</pre>

    <pre>the method of getting the ay vector would be:</pre>

    <pre>    ay = n * ax.

    scale ay to unit length.

</pre>

    <pre>c.1.6  writing dxf interface programs</pre>

    <pre>writing a program that communicates with autocad via the dxf mechanism

often appears far more difficult than it really is.  the dxf file contains

a seemingly overwhelming amount of information, and examining a dxf file

manually may lead to the conclusion that the task is hopeless.</pre>

    <pre>however, the dxf file has been designed to be easy to process by program,

not manually.  the format was constructed with the deliberate intention of

making it easy to ignore information you don't care about while easily

reading the information you need.  just remember to handle the groups in

any order and ignore any group you don't care about, and you'll be home

free.</pre>

    <pre>as an example, the following is a microsoft basic program that reads a dxf

file and extracts all the line entities from the drawing (ignoring lines

that appear inside blocks).  it prints the endpoints of these lines on the

screen.  as an exercise you might try entering this program into your com-

puter, running it on a dxf file from one of your drawings, then enhancing

it to print the center point and radius of any circles it encounters.  this

program is not put forward as an example of clean programming technique nor

the way a general dxf processor should be written; it is presented as an

example of just how simple a dxf-reading program can be.</pre>

    <pre>    1000 rem

    1010 rem extract lines from dxf file

    1020 rem

    1030 g1% = 0

    1040 line input &quot;dxf file name: &quot;; a$

    1050 open &quot;i&quot;, 1, a$ + &quot;.dxf&quot;

    1060 rem

    1070 rem ignore until section start encountered

    1080 rem

    1090 gosub 2000

    1100 if g% &lt;&gt; 0 then 1090

    1110 if s$ &lt;&gt; &quot;section&quot; then 1090

</pre>

    <pre>20

&#12;                                   (c) drawing interchange and file formats</pre>

    <pre>    1120 gosub 2000

    1130 rem

    1140 rem skip unless entities section

    1150 rem

    1160 if s$ &lt;&gt; &quot;entities&quot; then 1090

    1170 rem

    1180 rem scan until end of section, processing lines

    1190 rem

    1200 gosub 2000

    1210 if g% = 0 and s$ = &quot;endsec&quot; then 2200

    1220 if g% = 0 and s$ = &quot;line&quot; then gosub 1400 : goto 1210

    1230 goto 1200

    1400 rem

    1410 rem accumulate line entity groups

    1420 rem

    1430 gosub 2000

    1440 if g% = 10 then x1 = x : y1 = y : z1 = z

    1450 if g% = 11 then x2 = x : y2 = y : z2 = z

    1460 if g% = 0 then print &quot;line from (&quot;;x1;&quot;,&quot;;y1;&quot;,&quot;;z1;&quot;) to (&quot;;x2;

                              &quot;,&quot;;y2;&quot;,&quot;;z2;&quot;)

    1470 goto 1430

    2000 rem

    2010 rem read group code and following value

    2020 rem for x coordinates, read y and possibly z also

    2030 rem

    2040 if g1% &lt; 0 then g% = -g1% : g1% = 0 else input #1, g%

    2050 if g% &lt;   10 or  g% =  999 then line input #1, s$ : return

    2060 if g% &gt;=  38 and g% &lt;=  49 then input #1, v : return

    2080 if g% &gt;=  50 and g% &lt;=  59 then input #1, a : return

    2090 if g% &gt;=  60 and g% &lt;=  69 then input #1, p% : return

    2100 if g% &gt;=  70 and g% &lt;=  79 then input #1, f% : return

    2110 if g% &gt;= 210 and g% &lt;= 219 then 2130

    2120 if g% &gt;=  20 then print &quot;invalid group code&quot;;g% : stop

    2130 input #1, x

    2140 input #1, g1%

    2150 if g1% &lt;&gt; (g%+10) then print &quot;invalid y coord code&quot;;g1% : stop

    2160 input #1, y

    2170 input #1, g1%

    2180 if g1% &lt;&gt; (g%+20) then g1% = -g1% else input #1, z

    2190 return

    2200 close 1</pre>

    <pre>writing a program that constructs a dxf file is more difficult, because you

must maintain consistency within the drawing in order for autocad to find

it acceptable.  autocad allows you to omit many items in a dxf file and

still obtain a usable drawing.  the entire header section can be omitted if

you don't need to set any header variables.  any of the tables in the

tables section can be omitted if you don't need to make any entries, and in

fact the entire tables section can be dropped if nothing in it is required.

if you define any linetypes in the ltype table, this table must appear

before the layer table.  if no block definitions are used in the drawing,

the blocks section can be omitted.  if present, however, it must appear

before the entities section.  within the entities section, you can refer-

ence layer names even though you haven't defined them in the layer table.</pre>

    <pre>                                                                         21

&#12;autocad reference manual</pre>

    <pre>such layers will be automatically created with color 7 and the continuous

linetype.  the eof item must be present at the end of file.</pre>

    <pre>the following microsoft basic program constructs a dxf file representing a

polygon with a specified number of sides, leftmost origin point, and side

length.  this program supplies only the entities section of the dxf file,

and places all entities generated on the default layer &quot;0&quot;.  this may be

taken as an example of a minimum dxf generation program.  since this pro-

gram doesn't create the drawing header, the drawing limits, extents, and

current view will be invalid after performing a dxfin on the drawing gener-

ated by this program.  you can do a &quot;zoom e&quot; to fill the screen with the

drawing generated.  then adjust the limits manually.</pre>

    <pre>    1000 rem

    1010 rem polygon generator

    1020 rem

    1030 line input &quot;drawing (dxf) file name: &quot;; a$

    1040 open &quot;o&quot;, 1, a$ + &quot;.dxf&quot;

    1050 print #1, 0

    1060 print #1, &quot;section&quot;

    1070 print #1, 2

    1080 print #1, &quot;entities&quot;

    1090 pi = atn(1) * 4

    1100 input &quot;number of sides for polygon: &quot;; s%

    1110 input &quot;starting point (x,y): &quot;; x, y

    1120 input &quot;polygon side: &quot;; d

    1130 a1 = (2 * pi) / s%

    1140 a = pi / 2

    1150 for i% = 1 to s%

    1160 print #1, 0

    1170 print #1, &quot;line&quot;

    1180 print #1, 8

    1190 print #1, &quot;0&quot;

    1200 print #1, 10

    1210 print #1, x

    1220 print #1, 20

    1230 print #1, y

    1240 print #1, 30

    1250 print #1, 0.0

    1260 nx = d * cos(a) + x

    1270 ny = d * sin(a) + y

    1280 print #1, 11

    1290 print #1, nx

    1300 print #1, 21

    1310 print #1, ny

    1320 print #1, 31

    1330 print #1, 0.0

    1340 x = nx

    1350 y = ny

    1360 a = a + a1

    1370 next i%

    1380 print #1, 0

    1390 print #1, &quot;endsec&quot;</pre>

    <pre>22

&#12;                                   (c) drawing interchange and file formats</pre>

    <pre>    1400 print #1, 0

    1410 print #1, &quot;eof&quot;

    1420 close 1</pre>

    <pre>the dxfin command is relatively forgiving with respect to the format of

data items.  as long as a properly formatted item appears on the line on

which the data is expected, dxfin will accept it (of course, string items

should not have leading spaces unless these are intended to be part of the

string).  the above program takes advantage of this flexibility in input

format, and does not go to great effort to generate a file appearing

exactly like one generated by autocad.</pre>

    <pre>in the case of error loading a dxf file using dxfin, autocad reports the

error with a message indicating the nature of the error detected and the

last line processed in the dxf file before the error was detected.  this

may not be the line on which the error occurred, especially in the case of

such errors as omission of required groups.



</pre>

    <pre>c.2  binary drawing interchange files</pre>

    <pre>the ascii dxf file format described in the preceding sections of this

appendix is a complete representation of an autocad drawing in an ascii

text form easily processed by other programs.  in addition, autocad can

produce or read a binary form of the full dxf file, and accepts limited

input in another binary file format.  these binary files are described in

the following sections.

</pre>

    <pre>c.2.1  binary dxf files</pre>

    <pre>the dxfout command provides a &quot;binary&quot; option that writes binary dxf files.

such a file contains all of the information present in an ascii dxf file,

but in a much more compact form that takes, typically, 25% less file space

and can be read and written more quickly (typically 5 times faster) by

autocad.  unlike ascii dxf files, which entail a trade-off between size and

floating-point accuracy, binary dxf files preserve all of the accuracy in

the drawing database.  autocad release 10 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -