home *** CD-ROM | disk | FTP | other *** search
/ Avalon - 3D Objects & Resources / Avalon.iso / frmtspcs / dxfver10.txt < prev    next >
Text File  |  1995-01-01  |  96KB  |  2,354 lines

  1. Here is the Autodesk spec, and a C program that reads DXF:
  2.  
  3. [ This file is an excerpt from the AutoCAD Release 10 Reference Manual.
  4.   Copyright (C) 1988 Autodesk, Inc.  All rights reserved. ]
  5.  
  6.                                Appendix C
  7.                    Drawing Interchange and File Formats
  8.  
  9.  
  10. AutoCAD can be used by itself as a complete drawing editor.  In some appli-
  11. cations, however, other programs must examine drawings created by AutoCAD
  12. or generate drawings to be viewed, modified, or plotted with AutoCAD.
  13.  
  14. For example, if you've made an architectural drawing with AutoCAD, using
  15. INSERTed parts to represent windows, doors, and so on, you can process the
  16. drawing file and produce a bill of materials of all the items used in the
  17. drawing, or even make energy use calculations based on the area and the
  18. number and type of windows used.  Another possible application is to use
  19. AutoCAD to describe structures that are then sent to a large computer for
  20. finite element structural analysis.  You can compute stresses and displace-
  21. ments and send back information to display the deformed structure as an
  22. AutoCAD drawing.
  23.  
  24. Since the AutoCAD drawing database (.dwg file) is written in a very compact
  25. format that changes significantly from time to time as new features are
  26. added, we do not document its format and do not recommend that you attempt
  27. to write programs to read it directly.  To assist in interchanging drawings
  28. between AutoCAD and other programs, a "Drawing Interchange" file format
  29. (DXF(tm)) has been defined.  All implementations of AutoCAD accept this
  30. format and are able to convert it to and from their internal drawing file
  31. representation.
  32.  
  33. AutoCAD also supports the Initial Graphics Exchange Standard (IGES) file
  34. format.  The information comprising an AutoCAD drawing can be written out
  35. in IGES format, and IGES files can be read and converted to AutoCAD's
  36. internal format.
  37.  
  38.  
  39. C.1  ASCII Drawing Interchange (DXF) Files
  40.  
  41. This section describes AutoCAD's DXF (drawing interchange) file format and
  42. the commands provided to read and write these files.  DXF files are stan-
  43. dard ASCII text files.  They can easily be translated to the formats of
  44. other CAD systems, or submitted to other programs for specialized analysis.
  45.  
  46.  
  47. C.1.1  DXFOUT Command - Writing a DXF File
  48.  
  49. You can generate a drawing interchange file from an existing drawing by
  50. means of the Drawing Editor's DXFOUT command.  The command format is:
  51.  
  52.     Command:  DXFOUT   File name <default>:  (name or RETURN)
  53.  
  54. The default name for the output file is the same as that of the current
  55. drawing, but with a file type of ".dxf".  If you specify an explicit file
  56. name, do not include a file type; ".dxf" is assumed.  If a file with the
  57. same name already exists, it is deleted.  Next, DXFOUT asks what precision
  58.  
  59.                                                                           1
  60. AutoCAD Reference Manual
  61.  
  62. you want for floating-point numbers and permits output of a partial DXF
  63. file containing only selected objects.
  64.  
  65.     Enter decimal places of accuracy (0 to 16)/Entities/Binary <6>:
  66.  
  67. The "Binary" option is described later in this appendix. If you respond
  68. with "Entities" (or just "E"), DXFOUT will ask you to select the objects
  69. you want written to the DXF file.  Only the objects you select will be
  70. included in the output file - symbol tables (including Block Definitions)
  71. will not be included.  Once you've selected the desired objects, AutoCAD
  72. will prompt again for the numeric precision:
  73.  
  74.     Enter decimal places of accuracy (0 to 16)/Binary <6>:
  75.  
  76.  
  77. C.1.2  DXFIN Command - Loading a DXF File
  78.  
  79. A drawing interchange file can be converted into an AutoCAD drawing by
  80. means of the DXFIN command.  First enter the Drawing Editor using the
  81. "Create new drawing" task from the Main Menu.  Then issue the DXFIN com-
  82. mand.
  83.  
  84.     Command:  DXFIN   File name:  (name)
  85.  
  86. Enter the name of the drawing interchange file to be loaded.
  87.  
  88.  
  89. Full DXFIN
  90.  
  91. To load a complete DXF file, you must use DXFIN in an empty drawing, before
  92. any entities have been drawn and before any additional Block definitions,
  93. layers, linetypes, text styles, named views, named coordinate systems, or
  94. named viewport configurations have been created.  (If your prototype draw-
  95. ing contains any such items, use Main Menu Task 1's "name=" technique to
  96. create a new drawing without a prototype.)
  97.  
  98. If any errors are detected during the input, the new drawing is discarded.
  99. Otherwise, an automatic "ZOOM All" is performed to set the drawing extents.
  100.  
  101.  
  102. Partial DXFIN
  103.  
  104. If the current drawing is not empty, DXFIN loads only the ENTITIES section
  105. of the DXF file, adding the entities found there to the current drawing.
  106. In this case, DXFIN displays the message:
  107.  
  108.     Not a new drawing -- only ENTITIES section will be input.
  109.  
  110. If errors are detected during such partial DXF input, the drawing is
  111. returned to the state it was in before the DXFIN command.  Otherwise, the
  112. newly added entities are drawn.
  113.  
  114.  
  115.  
  116. 2
  117.                                    (C) Drawing Interchange and File Formats
  118.  
  119. C.1.3  DXF File Format
  120.  
  121. This section describes the format of a DXF file in detail.  It contains a
  122. great deal of technical information that you need only if you're writing
  123. your own program to process DXF files.  Otherwise, you can skip this sec-
  124. tion.
  125.  
  126. It would probably be helpful to produce a DXF file from a small drawing,
  127. print it out, and refer to it occasionally while reading the information
  128. presented below.
  129.  
  130.  
  131. C.1.3.1  General File Structure
  132.  
  133. A Drawing Interchange File is simply an ASCII text file with a file type of
  134. ".dxf" and specially-formatted text.  The overall organization of a DXF
  135. file is as follows:
  136.  
  137.   1. HEADER section - General information about the drawing is found in
  138.      this section of the DXF file.  Each parameter has a variable name
  139.      and an associated value.
  140.  
  141.   2. TABLES section -- This section contains definitions of named
  142.      items.
  143.  
  144.        o  Linetype (LTYPE) table
  145.        o  Layer table
  146.        o  Text style (STYLE) table
  147.        o  View table
  148.        o  User Coordinate System (UCS) table
  149.        o  Viewport configuration (VPORT) table
  150.        o  Drawing manager (DWGMGR) table (for future use)
  151.  
  152.   3. BLOCKS section - This section contains Block Definition entities
  153.      describing the entities comprising each Block in the drawing.
  154.  
  155.   4. ENTITIES section - This section contains the drawing entities,
  156.      including any Block References.
  157.  
  158.   5. END OF FILE
  159.  
  160. If you use DXFOUT's "Entities" option, the resulting DXF file will contain
  161. only the ENTITIES and END OF FILE sections, and the ENTITIES section will
  162. reflect only the objects you select for output.
  163.  
  164. A DXF file is composed of a multiplicity of groups, each of which occupies
  165. two lines in the DXF file.  The first line of a group is a group code,
  166. which is a positive nonzero integer output in FORTRAN "I3" format (that is,
  167. right justified and blank filled in a three character field).  The second
  168. line of the group is the group value, in a format which depends on the type
  169. of the group as specified by the group code.
  170.  
  171.  
  172.  
  173.                                                                           3
  174. AutoCAD Reference Manual
  175.  
  176. The specific assignment of group codes depends upon the item being
  177. described in the file.  However, the type of the value this group supplies
  178. is derived from the group code in the following way:
  179.  
  180.                     Group code range   Following value
  181.                           0 - 9       String
  182.                          10 - 59      Floating-point
  183.                          60 - 79      Integer
  184.                         210 - 239     Floating-point
  185.                            999        Comment (string)
  186.  
  187. Thus a program can easily read the value following a group code without
  188. knowing the particular use of this group in an item in the file.  The
  189. appearance of values in the DXF file is not affected by the setting of the
  190. UNITS command: coordinates are always represented as decimal (or possibly
  191. scientific notation if very large) numbers, and angles are always repre-
  192. sented in decimal degrees with zero degrees to the east of origin.
  193.  
  194. Variables, table entries, and entities are described by a group that intro-
  195. duces the item, giving its type and/or name, followed by multiple groups
  196. that supply the values associated with the item.  In addition, special
  197. groups are used for file separators such as markers for the beginning and
  198. end of sections, tables, and the file itself.
  199.  
  200. Entities, table entries, and file separators are always introduced with a 0
  201. group code that is followed by a name describing the item.
  202.  
  203.  
  204. C.1.3.2  Group Codes
  205.  
  206. Group codes are used both to indicate the type of the value of the group,
  207. as explained above, and to indicate the general use of the group.  The spe-
  208. cific function of the group code depends on the actual variable, table
  209. item, or entity description.  This section indicates the general use of
  210. groups, noting as "(fixed)" any that always have the same function.
  211.  
  212.    Group code                           Value type
  213.        0        Identifies the start of an entity, table entry, or file
  214.                 separator.  The text value that follows indicates which.
  215.        1        The primary text value for an entity.
  216.        2        A name; Attribute tag, Block name, etc.
  217.       3-4       Other textual or name values.
  218.        5        Entity handle expressed as a hexadecimal string.
  219.        6        Line type name (fixed).
  220.        7        Text style name (fixed).
  221.        8        Layer name (fixed).
  222.        9        Variable name identifier (used only in HEADER section of
  223.                 the DXF file).
  224.        10       Primary X coordinate (start point of a Line or Text
  225.                 entity, center of a Circle, etc.).
  226.      11-18      Other X coordinates.
  227.                                                              continued ...
  228.  
  229.  
  230. 4
  231.                                    (C) Drawing Interchange and File Formats
  232.  
  233.    Group code                           Value type
  234.        20       Primary Y coordinate.  2n values always correspond to 1n
  235.                 values and immediately follow them in the file.
  236.      21-28      Other Y coordinates.
  237.        30       Primary Z coordinate.  3n values always correspond to 1n
  238.                 and 2n values and immediately follow them in the file.
  239.      31-37      Other Z coordinates.
  240.        38       This entity's elevation if nonzero (fixed).  Output only
  241.                 if system variable FLATLAND is set to 1.
  242.        39       This entity's thickness if nonzero (fixed).
  243.      40-48      Floating-point values (text height, scale factors, etc.).
  244.        49       Repeated value - multiple 49 groups may appear in one
  245.                 entity for variable length tables (such as the dash
  246.                 lengths in the LTYPE table).  A 7x group always appears
  247.                 before the first 49 group to specify the table length.
  248.      50-58      Angles.
  249.        62       Color number (fixed).
  250.        66       "Entities follow" flag (fixed).
  251.      70-78      Integer values, such as repeat counts, flag bits, or
  252.                 modes.
  253.  210, 220, 230  X, Y, and Z components of extrusion direction.
  254.       999       Comments
  255.  
  256.  
  257. C.1.4  Comments
  258.  
  259. The 999 group code indicates that the following line is a comment string.
  260. DXFOUT does not currently include such groups in its output file, but DXFIN
  261. honors them and ignores the comments.  Thus, you can use the 999 group to
  262. include comments in a DXF file you've edited.  For example:
  263.  
  264.     999
  265.     This is a comment.
  266.     999
  267.     This is another comment.
  268.  
  269.  
  270. C.1.5  File Sections
  271.  
  272. The DXF file is subdivided into four sections.  File separator groups are
  273. used to delimit these file sections.  The following is an example of a void
  274. DXF file with only the section markers and table headers present.
  275.  
  276.       0                           (Begin HEADER section)
  277.     SECTION
  278.       2
  279.     HEADER
  280.         <<<<Header variable items go here>>>>
  281.       0
  282.     ENDSEC                        (End HEADER section)
  283.       0                           (Begin TABLES section)
  284.     SECTION
  285.       2
  286.  
  287.                                                                           5
  288. AutoCAD Reference Manual
  289.  
  290.     TABLES
  291.       0
  292.     TABLE
  293.       2
  294.     VPORT
  295.      70
  296.     (viewport table maximum item count)
  297.         <<<<viewport table items go here>>>>
  298.       0
  299.     ENDTAB
  300.       0
  301.     TABLE
  302.       2
  303.     LTYPE, LAYER, STYLE, VIEW, UCS, or DWGMGR
  304.      70
  305.     (Table maximum item count)
  306.         <<<<Table items go here>>>>
  307.       0
  308.     ENDTAB
  309.       0
  310.     ENDSEC                        (End TABLES section)
  311.       0                           (Begin BLOCKS section)
  312.     SECTION
  313.       2
  314.     BLOCKS
  315.         <<<<Block definition entities go here>>>>
  316.       0
  317.     ENDSEC                        (End BLOCKS section)
  318.       0                           (Begin ENTITIES section)
  319.     SECTION
  320.       2
  321.     ENTITIES
  322.         <<<<Drawing entities go here>>>>
  323.       0
  324.     ENDSEC                        (End ENTITIES section)
  325.       0
  326.     EOF                           (End of file)
  327.  
  328.  
  329. C.1.5.1  HEADER Section
  330.  
  331. The HEADER section of the DXF file contains settings of variables
  332. associated with the drawing.  These variables are set with various commands
  333. and are the type of information displayed by the STATUS command.  Each
  334. variable is specified in the header section by a 9 group giving its name,
  335. followed by groups that supply its value.  The header variables, the groups
  336. that follow, and their meanings are listed below.
  337.  
  338. Although this list is very similar to the list of system variables in
  339. Appendix A, the two lists are not identical.  Be sure you're referring to
  340. the proper list.
  341.  
  342.  
  343.  
  344. 6
  345.                                    (C) Drawing Interchange and File Formats
  346.  
  347.   $ACADVER       1     the AutoCAD drawing database version number.
  348.   $ANGBASE      50     Angle 0 direction.
  349.   $ANGDIR       70     1=clockwise angles, 0=counterclockwise.
  350.   $ATTDIA       70     Attribute entry dialogues, 1 = on, 0 = off
  351.   $ATTMODE      70     Attribute visibility: 0=none, 1=normal, 2=all.
  352.   $ATTREQ       70     Attribute prompting during INSERT, 1 = on, 0 = off
  353.   $AUNITS       70     UNITS format for angles.
  354.   $AUPREC       70     UNITS precision for angles.
  355.   $AXISMODE     70     axis on if nonzero.
  356.   $AXISUNIT   10,20    axis X and Y tick spacing.
  357.   $BLIPMODE     70     blip mode on if nonzero.
  358.   $CECOLOR      62     entity color number; 0 = BYBLOCK, 256 = BYLAYER.
  359.   $CELTYPE       6     entity linetype name, or BYBLOCK or BYLAYER.
  360.   $CHAMFERA     40     first chamfer distance.
  361.   $CHAMFERB     40     second chamfer distance.
  362.   $CLAYER        8     current layer name.
  363.   $COORDS       70     0=static coordinate display, 1=continuous update,
  364.                        2="d<a" format.
  365.   $DIMALT       70     alternate unit dimensioning performed if nonzero.
  366.   $DIMALTD      70     alternate unit decimal places.
  367.   $DIMALTF      40     alternate unit scale factor.
  368.   $DIMAPOST      1     alternate dimensioning suffix
  369.   $DIMASO       70     1=create associative dimensioning, 0=draw
  370.                        individual entities.
  371.   $DIMASZ       40     dimensioning arrow size.
  372.   $DIMBLK        2     arrow block name.
  373.   $DIMBLK1       1     first arrow block name.
  374.   $DIMBLK2       1     second arrow block name.
  375.   $DIMCEN       40     size of center mark/lines.
  376.   $DIMDLE       40     dimension line extension.
  377.   $DIMDLI       40     dimension line increment.
  378.   $DIMEXE       40     extension line extension.
  379.   $DIMEXO       40     extension line offset.
  380.   $DIMLFAC      40     linear measurements scale factor.
  381.   $DIMLIM       70     dimension limits generated if nonzero.
  382.   $DIMPOST       1     general dimensioning suffix
  383.   $DIMRND       40     rounding value for dimension distances.
  384.   $DIMSAH       70     use separate arrow blocks if nonzero.
  385.   $DIMSCALE     40     overall dimensioning scale factor.
  386.   $DIMSE1       70     first extension line suppressed if nonzero.
  387.   $DIMSE2       70     second extension line suppressed if nonzero.
  388.   $DIMSHO       70     1=Recompute dimensions while dragging,
  389.                        0=drag original image.
  390.   $DIMSOXD      70     suppress outside-extensions dimension lines
  391.                        if nonzero.
  392.   $DIMTAD       70     text above dimension line if nonzero.
  393.   $DIMTIH       70     text inside horizontal if nonzero.
  394.   $DIMTIX       70     force text inside extensions if nonzero.
  395.   $DIMTM        40     minus tolerance.
  396.   $DIMTOFL      70     if text outside extensions, force line between
  397.                        extensions if nonzero.
  398.   $DIMTOH       70     text outside horizontal if nonzero.
  399.  
  400.  
  401.                                                                           7
  402. AutoCAD Reference Manual
  403.  
  404.   $DIMTOL       70     dimension tolerances generated if nonzero.
  405.   $DIMTP        40     plus tolerance.
  406.   $DIMTSZ       40     dimensioning tick size: 0=no ticks.
  407.   $DIMTVP       40     text vertical position.
  408.   $DIMTXT       40     dimensioning text height.
  409.   $DIMZIN       70     zero suppression for "feet & inch" dimensions.
  410.   $DRAGMODE     70     0=off, 1=on, 2=auto.
  411.   $ELEVATION    40     current elevation set by ELEV command.
  412.   $EXTMAX    10,20,30  XY drawing extents upper right corner (in WCS).
  413.   $EXTMIN    10,20,30  XY drawing extents lower left corner (in WCS).
  414.   $FILLETRAD    40     fillet radius.
  415.   $FILLMODE     70     FILL mode on if nonzero.
  416.   $FLATLAND     70     force compatibility with older versions if nonzero.
  417.   $HANDLING     70     handles enabled if nonzero.
  418.   $HANDSEED      5     next available handle.
  419.   $INSBASE   10,20,30  insertion base set by BASE command (in WCS).
  420.   $LIMCHECK     70     nonzero if limits checking is on.
  421.   $LIMMAX     10,20    XY drawing limits upper right corner (in WCS).
  422.   $LIMMIN     10,20    XY drawing limits lower left corner (in WCS).
  423.   $LTSCALE      40     global linetype scale.
  424.   $LUNITS       70     UNITS format for coordinates and distances.
  425.   $LUPREC       70     UNITS precision for coordinates and distances.
  426.   $MENU          1     name of menu file.
  427.   $MIRRTEXT     70     MIRROR text if nonzero.
  428.   $ORTHOMODE    70     ORTHO mode on if nonzero.
  429.   $OSMODE       70     running object snap modes.
  430.   $PDMODE       70     point display mode.
  431.   $PDSIZE       40     point display size.
  432.   $PLINEWID     40     default Polyline width.
  433.   $QTEXTMODE    70     quick text mode on if nonzero.
  434.   $REGENMODE    70     REGENAUTO mode on if nonzero.
  435.   $SKETCHINC    40     sketch record increment.
  436.   $SKPOLY       70     0=sketch lines, 1=sketch polylines.
  437.   $SPLFRAME     70     spline control polygon display, 1 = on, 0 = off.
  438.   $SPLINESEGS   70     number of line segments per spline patch.
  439.   $SPLINETYPE   70     spline curve type for "PEDIT Spline"
  440.                        (see Appendix A).
  441.   $SURFTAB1     70     number of mesh tabulations in first direction.
  442.   $SURFTAB2     70     number of mesh tabulations in second direction.
  443.   $SURFTYPE     70     surface type for "PEDIT Smooth" (see Appendix A).
  444.   $SURFU        70     surface density (for "PEDIT Smooth") in M direction.
  445.   $SURFV        70     surface density (for "PEDIT Smooth") in N direction.
  446.   $TDCREATE     40     date/time of drawing creation.
  447.   $TDINDWG      40     cumulative editing time for this drawing.
  448.   $TDUPDATE     40     date/time of last drawing update.
  449.   $TDUSRTIMER   40     user elapsed timer.
  450.   $TEXTSIZE     40     default text height.
  451.   $TEXTSTYLE     7     current text style name.
  452.   $THICKNESS    40     current thickness set by ELEV command.
  453.   $TRACEWID     40     default Trace width.
  454.   $UCSNAME       1     Name of current UCS.
  455.   $UCSORG    10,20,30  origin of current UCS (in WCS).
  456.  
  457.  
  458. 8
  459.                                    (C) Drawing Interchange and File Formats
  460.  
  461.   $UCSXDIR   10,20,30  direction of current UCS's X axis
  462.                        (in World coordinates).
  463.   $UCSYDIR   10,20,30  direction of current UCS's Y axis
  464.                        (in World coordinates).
  465.   $USERI1 - 5   70     Five integer variables intended for use by
  466.                        third-party developers.
  467.   $USERR1 - 5   40     Five real variables intended for use by
  468.                        third-party developers.
  469.   $USRTIMER     70     0=timer off, 1=timer on.
  470.   $WORLDVIEW    70     1=set UCS to WCS during DVIEW/VPOINT,
  471.                        0=don't change UCS
  472.  
  473. The header variables listed below existed prior to AutoCAD Release 10 but
  474. now have independent settings for each active viewport.  They are not
  475. output by DXFOUT unless system variable FLATLAND is set to 1.  DXFIN honors
  476. these variables when read from DXF files, but if a VPORT symbol table with
  477. "*ACTIVE" entries is present (as is true for any DXF file produced by
  478. Release 10 or higher), the values in the VPORT table entries will override
  479. the values of these header variables.
  480.  
  481.   $FASTZOOM     70     fast zoom enabled if nonzero.
  482.   $GRIDMODE     70     grid mode on if nonzero.
  483.   $GRIDUNIT   10,20    grid X and Y spacing.
  484.   $SNAPANG      50     snap grid rotation angle.
  485.   $SNAPBASE   10,20    snap/grid base point (in UCS).
  486.   $SNAPISOPAIR  70     isometric plane: 0=left, 1=top, 2=right.
  487.   $SNAPMODE     70     snap mode on if nonzero.
  488.   $SNAPSTYLE    70     snap style: 0=standard, 1=isometric.
  489.   $SNAPUNIT   10,20    snap grid X and Y spacing.
  490.   $VIEWCTR    10,20    XY center of current view on screen.
  491.   $VIEWDIR   10,20,30  viewing direction (direction from target, in WCS).
  492.   $VIEWSIZE     40     height of view.
  493.  
  494. The date/time variables ($TDCREATE and $TDUPDATE) are output as real num-
  495. bers in the format:
  496.  
  497.     <Julian date>.<Fraction>
  498.  
  499. The elapsed time variables ($TDINDWG and $TDUSRTIMER) have a similar
  500. format:
  501.  
  502.     <Number of days>.<Fraction>
  503.  
  504.  
  505. C.1.5.2  TABLES Section
  506.  
  507. The TABLES section contains several tables, each of which in turn contains
  508. a variable number of table entries. The order of the tables may change, but
  509. the LTYPE table will always precede the LAYER table.  Each table is intro-
  510. duced with a 0 group with the label "TABLE".  This is followed by a 2 group
  511. identifying the particular table (VPORT, LTYPE, LAYER, STYLE, VIEW, UCS, or
  512. DWGMGR) and a 70 group that specifies the maximum number of table entries
  513.  
  514.                                                                           9
  515. AutoCAD Reference Manual
  516.  
  517. that may follow. The tables in a drawing may contain deleted items, but
  518. these are not written to the DXF file.  Thus, fewer table entries may
  519. follow the table header than are indicated by the 70 group, so don't use
  520. the count in the 70 group as an index to read in the table.  It is provided
  521. so that your program to read DXF files can allocate an array in advance
  522. large enough to hold all the table entries that follow.
  523.  
  524. Following this header for each table are the table entries.  Each table
  525. item consists of a 0 group identifying the item type (same as table name,
  526. e.g., "LTYPE" or "LAYER"), a 2 group giving the name of the table entry, a
  527. 70 group specifying flags relevant to the table entry (defined for each
  528. table below), and additional groups that give the value of the table entry.
  529. The end of each table is indicated by a 0 group with the value "ENDTAB".
  530.  
  531. If any table entry has bit value 64 set in its group 70 flags, the table
  532. entry was referenced by at least one entity in the drawing the last time
  533. the drawing editor was entered to edit this drawing.  This "referenced"
  534. flag is for the benefit of the PURGE command; it can be ignored by most
  535. programs that read DXF files, and need not be set by programs that write
  536. DXF files.
  537.  
  538. The following are the groups used for each type of table item.  All groups
  539. are present for each table item.
  540.  
  541.   LTYPE    3 (descriptive text for linetype), 72 (alignment code), 73
  542.            (number of dash length items), 40 (total pattern length), 49
  543.            (dash length 1), 49 (dash length 2), . . .
  544.  
  545.   LAYER    62 (color number, negative if layer is off), 6 (linetype
  546.            name).  The 1 bit is set in the 70 group flags if the layer is
  547.            frozen.
  548.  
  549.   STYLE    40 (fixed text height; 0 if not fixed), 41 (width factor), 50
  550.            (obliquing angle), 71 (text generation flags), 42 (last height
  551.            used), 3 (primary font file name), 4 ("bigfont" file name;
  552.            blank if none).  If the third bit (4) is set in the 70 group
  553.            flags, this is a vertically-oriented text style.
  554.  
  555.            A STYLE table item is used to record shape file LOAD requests
  556.            also.  In this case the first bit (1) is set in the 70 group
  557.            flags and only the 3 group (shape file name) is meaningful
  558.            (all the other groups are output, however).
  559.  
  560.            The "text generation flags" are a bit-coded field with the
  561.            following bit meanings:
  562.  
  563.                 Flag bit value                Meaning
  564.                        2        Text is backwards (mirrored in X)
  565.                        4        Text is upside down (mirrored in Y)
  566.  
  567.  
  568.  
  569.  
  570.  
  571. 10
  572.                                    (C) Drawing Interchange and File Formats
  573.  
  574.   VIEW     40 and 41 (view height and width), 10 and 20 (view center
  575.            point), 11, 21, 31 (view direction from target, in WCS), 12,
  576.            22, 32 (target point, in WCS), 42 (lens length), 43 and 44
  577.            (front and back clipping planes-offsets from target point), 50
  578.            (twist angle), 71 view mode (see VIEWMODE system variable
  579.            Appendix A).
  580.  
  581.   UCS      10, 20, 30 (origin), 11, 21, 31 (X axis direction), 12, 22, 32
  582.            (Y axis direction).  All in World coordinates.
  583.  
  584.   VPORT    10 and 20 (lower left corner of viewport; 0.0 to 1.0), 11 and
  585.            21 (upper right corner), 12 and 22 (view center point), 13 and
  586.            23 (snap base point), 14 and 24 (snap spacing, X and Y), 15
  587.            and 25 (grid spacing, X and Y), 16, 26, 36 (view direction
  588.            from target point), 17, 27, 37 (view target point), 40 (view
  589.            height), 41 (viewport aspect ratio), 42 (lens length), 43 and
  590.            44 (front and back clipping planes; offsets from target
  591.            point), 50 (snap rotation angle), 51 (view twist angle), 71
  592.            (view mode; see VIEWMODE system variable in Appendix A), 72
  593.            (circle zoom percent), 73 (fast zoom setting), 74 (UCSICON
  594.            setting), 75 (snap on/off), 76 (grid on/off), 77 (snap style),
  595.            78 (snap isopair).
  596.  
  597.            The VPORT table is unique in that it may contain several
  598.            entries with the same name (indicating a multiple-viewport
  599.            configuration).  The entries corresponding to the active view-
  600.            port configuration all have the name "*ACTIVE".  The first
  601.            such entry describes the current viewport.
  602.  
  603.   DWGMGR   For future use.  Fields not yet defined.
  604.  
  605.  
  606. C.1.5.3  BLOCKS Section
  607.  
  608. The BLOCKS section of the DXF file contains all the Block Definitions.
  609. This section contains the entities that make up the Blocks used in the
  610. drawing, including "anonymous" Blocks generated by the HATCH command and by
  611. associative dimensioning.  The format of the entities in this section is
  612. identical to those in the ENTITIES section described below, so refer to
  613. that section for details.  All entities in the BLOCKS section appear
  614. between BLOCK and ENDBLK entities.  BLOCK and ENDBLK entities appear only
  615. in the BLOCKS section.  Block definitions are never nested (that is, no
  616. BLOCK or ENDBLK entity ever appears within another BLOCK-ENDBLK pair).
  617.  
  618.  
  619. C.1.5.4  ENTITIES Section
  620.  
  621. Entity items appear in both the BLOCK and ENTITIES sections of the DXF
  622. file.  The appearance of entities in the two sections is identical, with
  623. the exception that entities in the BLOCK section never have handles. The
  624. following gives the format of each entity as it appears in the file.  Some
  625. groups that define an entity always appear, and some are optional and
  626. appear only if they differ from their default values.  In the following
  627.  
  628.                                                                          11
  629. AutoCAD Reference Manual
  630.  
  631. discussion, groups that always occur are given by their group number and
  632. function, while optional groups are indicated by "-optional N" following
  633. the group description.  "N" is the default value if the group is omitted.
  634.  
  635. Programs that read DXF files should not assume that the groups describing
  636. an entity occur in the order given here.  The end of the groups that make
  637. up an entity is indicated by the next 0 group, beginning the next entity or
  638. indicating the end of the section.
  639.  
  640. Remember that a DXF file is a complete representation of the drawing data-
  641. base, and that as AutoCAD is further enhanced, new groups will be added to
  642. entities to accommodate additional features.  Writing your DXF processing
  643. program in a table-driven way, making no assumptions about the order of
  644. groups in an entity, and ignoring any groups not presently defined, will
  645. make it much easier to accommodate DXF files from future releases of
  646. AutoCAD.
  647.  
  648. Each entity begins with a 0 group identifying the entity type.  The names
  649. used for the entities are given in the table that follows.  Every entity
  650. contains an 8 group that gives the name of the layer on which the entity
  651. resides.  Each entity may have elevation, thickness, linetype, or color
  652. information associated with it. If handles are enabled, every entity has a
  653. 5 group containing its handle (as a string representing a hexadecimal
  654. number). The following groups are included only if the entity has nonde-
  655. fault values for these properties.
  656.  
  657.   Group code                         Meaning
  658.        6      Linetype name (if not "BYLAYER").  The special name "BYBLOCK"
  659.               indicates a floating linetype.
  660.  
  661.       38      Elevation (if nonzero).  Output only if system variable
  662.               FLATLAND is 1.  Otherwise, Z coordinates are supplied as
  663.               3x-groups as part of each of the entity's defining points.
  664.  
  665.       39      Thickness (if nonzero).
  666.  
  667.       62      Color number (if not "BYLAYER").  Zero indicates the
  668.               "BYBLOCK" (floating) color.
  669.  
  670.      210,     These groups are included for each Line, Point, Circle, Shape,
  671.      220,     Text, Arc, Trace, Solid, Block Reference, Polyline, Dimension,
  672.      230      Attribute, and Attribute Definition entity if its extrusion
  673.               direction is not parallel to the World Z axis.  The indicate
  674.               the X, Y, and Z components of the entity's extrusion direction.
  675.  
  676. The rest of the groups that make up an entity item are described below.
  677. Many of the entities include "flag" groups.  These are integer codes (6x or
  678. 7x groups) that encode various pieces of information regarding the entity,
  679. and are specific to the particular entity type.  In the following descrip-
  680. tions, the term "bit-coded" means that the flag contains various true/false
  681. values coded as the sum of the bit values given.  Any bits not defined in
  682. the following section should be ignored in these fields and set to zero
  683. when constructing a DXF file.
  684.  
  685. 12
  686.                                    (C) Drawing Interchange and File Formats
  687.  
  688.   LINE      10, 20, 30 (start point), 11, 21, 31 (end point).
  689.  
  690.   POINT     10, 20, 30 (point), 50 (angle of X axis for the UCS in effect
  691.             when the Point was drawn -optional 0, for use when PDMODE is
  692.             nonzero).
  693.  
  694.   CIRCLE    10, 20, 30 (center), 40 (radius).
  695.  
  696.   ARC       10, 20, 30 (center), 40 (radius), 50 (start angle), 51 (end
  697.             angle).
  698.  
  699.   TRACE     Four points defining the corners of the trace: (10, 20, 30),
  700.             (11, 21, 31), (12, 22, 32), and (13, 23, 33).
  701.  
  702.   SOLID     Four points defining the corners of the solid: (10, 20, 30),
  703.             (11, 21, 31), (12, 22, 32), and (13, 23, 33).  If only three
  704.             points were entered (forming a triangular solid), the third
  705.             and fourth points will be the same.
  706.  
  707.   TEXT      10, 20, 30 (insertion point), 40 (height), 1 (text value), 50
  708.             (rotation angle -optional 0), 41 (relative X scale factor
  709.             -optional 1), 51 (obliquing angle -optional 0), 7 (text style
  710.             name -optional "STANDARD"), 71 (text generation flags
  711.             -optional 0), 72 (justification type -optional 0), 11, 21, 31
  712.             (alignment point -optional, appears only if 72 group is
  713.             present and nonzero).
  714.  
  715.             The "text generation flags" are a bit-coded field with mean-
  716.             ings as follows:
  717.  
  718.                  Flag bit value                Meaning
  719.                        2         Text is backwards (mirrored in X)
  720.                        4         Text is upside down (mirrored in Y)
  721.  
  722.             The "justification type" value (not bit-coded) indicates the
  723.             text justification style used on this entity, as shown in the
  724.             following table.
  725.  
  726.               Value                       Meaning
  727.                 0    Text is left justified
  728.                 1    Text is centered along its baseline
  729.                 2    Text is right justified
  730.                 3    Text is aligned between two points (height varies)
  731.                 4    Text is "middle" (fully) centered
  732.                 5    Text is fit between two points (width varies)
  733.  
  734.             If the justification is anything other than 0 (left justi-
  735.             fied), 11, 21, and 31 groups will also appear in the entity
  736.             to specify the alignment point of the text (center, right-
  737.             most, or second alignment point).
  738.  
  739.             DXFOUT handles ASCII control characters in text strings by
  740.             expanding the character into a "^" (caret) followed by the
  741.  
  742.                                                                          13
  743. AutoCAD Reference Manual
  744.  
  745.             appropriate letter.  For example, an ASCII Control-G (BEL,
  746.             decimal code 7) is output as "^G".  If the text itself con-
  747.             tains a caret character, it is expanded to "^ " (caret,
  748.             space).  DXFIN performs the complementary conversion.
  749.  
  750.   SHAPE     10, 20, 30 (insertion point), 40 (size), 2 (shape name), 50
  751.             (rotation angle -optional 0), 41 (relative X scale factor
  752.             -optional 1), 51 (obliquing angle -optional 0).
  753.  
  754.   BLOCK     2 (Block name), 70 (Block type flags), 10, 20, 30 (Block base
  755.             point).  Appears only in BLOCKS section.  The "Block type
  756.             flags" are bit-coded, with the following bit meanings:
  757.  
  758.               Flag bit value                   Meaning
  759.                     1         This is an "anonymous" Block generated by
  760.                               hatching, associative dimensioning, or
  761.                               other internal operations.
  762.                     2         This Block has Attributes.
  763.  
  764.   ENDBLK    No groups.  Appears only in BLOCKS section.
  765.  
  766.   INSERT    66 ("Attributes follow" flag -optional 0), 2 (Block name),
  767.             10, 20, 30 (insertion point), 41 (X scale factor -optional
  768.             1), 42 (Y scale factor -optional 1), 43 (Z scale factor
  769.             -optional 1), 50 (rotation angle -optional 0), 70 and 71
  770.             (column and row counts -optional 1), 44 and 45 (column and
  771.             row spacing -optional 0).
  772.  
  773.             If the value of the "Attributes follow" flag is 1, a series
  774.             of Attribute (ATTRIB) entities is expected to follow the
  775.             INSERT, terminated by a sequence end (SEQEND) entity.
  776.  
  777.   ATTDEF    10, 20, 30 (text start), 40 (text height), 1 (default value,
  778.             see TEXT above for handling of ASCII control characters), 3
  779.             (prompt string), 2 (tag string), 70 (Attribute flags), 73
  780.             (field length -optional 0), 50 (text rotation -optional 0),
  781.             41 (relative X scale factor -optional 1), 51 (obliquing angle
  782.             -optional 0), 7 (text style name -optional "STANDARD"), 71
  783.             (text generation flags -optional 0, see TEXT above), 72 (text
  784.             justification type -optional 0, see TEXT above)), 11, 21, 31
  785.             (alignment point -optional, appears only if 72 group is
  786.             present and nonzero).
  787.  
  788.             The "Attribute flags" are a bit-coded field in which the bits
  789.             have the following meanings:
  790.  
  791.               Flag bit value                   Meaning
  792.                     1         Attribute is invisible (does not display)
  793.                     2         This is a constant Attribute
  794.                     4         Verification is required on input of this
  795.                               Attribute.
  796.                     8         Attribute is preset (no prompt during
  797.                               insertion)
  798.  
  799. 14
  800.                                    (C) Drawing Interchange and File Formats
  801.  
  802.   ATTRIB    10, 20, 30 (text start), 40 (text height), 1 (value, see TEXT
  803.             above for handling of ASCII control characters), 2 (Attribute
  804.             tag), 70 (Attribute flags; see ATTDEF above), 73 (field
  805.             length -optional 0), 50 (text rotation -optional 0), 41 (rel-
  806.             ative X scale factor -optional 1), 51 (obliquing angle
  807.             -optional 0), 7 (text style name -optional "STANDARD"), 71
  808.             (text generation flags -optional 0, see TEXT above), 72 (text
  809.             justification type -optional 0, see TEXT above), 11, 21, 31
  810.             (alignment point -optional, appears only if 72 group is
  811.             present and nonzero).
  812.  
  813.   POLYLINE  66 ("vertices follow flag"), 70 (Polyline flags), 40 (default
  814.             starting width), 41 (default ending width), 71 and 72 (poly-
  815.             gon mesh M and N vertex counts -optional 0), 73 and 74
  816.             (smooth surface M and N densities -optional 0), 75 (smooth
  817.             surface type -optional 0).  The default widths apply to any
  818.             vertex that doesn't supply widths (see below).
  819.  
  820.             The "vertices follow" flag is always 1, indicating that a
  821.             series of VERTEX entities is expected to follow the POLYLINE,
  822.             terminated by a sequence end (SEQEND) entity.  The "polyline
  823.             flags" group is a bit-coded field with bits defined as fol-
  824.             lows:
  825.  
  826.              Flag bit value                    Meaning
  827.                     1        This is a closed Polyline (or a polygon
  828.                              mesh closed in the M direction)
  829.                     2        Curve-fit vertices have been added
  830.                     4        Spline-fit vertices have been added
  831.                     8        This is a 3D Polyline
  832.                    16        This is a 3D polygon mesh.  Group 75 indi-
  833.                              cates the smooth surface type, as follows:
  834.  
  835.                                0 = no smooth surface fitted
  836.                                5 = quadratic B-spline surface
  837.                                6 = cubic B-spline surface
  838.                                8 = Bezier surface
  839.  
  840.                    32        The polygon mesh is closed in the N direc-
  841.                              tion
  842.  
  843.   VERTEX    10, 20, 30 (location), 40 (starting width -optional, see
  844.             above), 41 (ending width -optional, see above), 42 (bulge),
  845.             70 (vertex flags), 50 (curve fit tangent direction
  846.             -optional).  The bulge is the tangent of 1/4 the included
  847.             angle for an arc segment, made negative if the arc goes
  848.             clockwise from the start point to the end point; a bulge of 0
  849.             indicates a straight segment, and a bulge of 1 is a semicir-
  850.             cle.  The meanings of the bit-coded "vertex flags" are shown
  851.             in the following table.
  852.  
  853.  
  854.  
  855.  
  856.                                                                          15
  857. AutoCAD Reference Manual
  858.  
  859.              Flag bit value                    Meaning
  860.                    1         Extra vertex created by curve fitting
  861.                    2         Curve fit tangent defined for this vertex.
  862.                              A curve fit tangent direction of 0 may be
  863.                              omitted from the DXF output, but is signif-
  864.                              icant if this bit is set.
  865.                    4         Unused (never set in DXF files)
  866.                    8         Spline vertex created by spline fitting
  867.                    16        Spline frame control point
  868.                    32        3D Polyline vertex
  869.                    64        3D polygon mesh vertex
  870.  
  871.   SEQEND    No fields.  This entity marks the end of vertices (VERTEX
  872.             type name) for a Polyline, or the end of Attribute entities
  873.             (ATTRIB type name) for an INSERT entity that has Attributes
  874.             (indicated by 66 group present and nonzero in INSERT entity).
  875.  
  876.   3DLINE    10, 20, 30 (start point), 11, 21, 31 (end point).
  877.  
  878.   3DFACE    Four points defining the corners of the face: (10, 20, 30),
  879.             (11, 21, 31), (12, 22, 32), and (13, 23, 33).  70 (invisible
  880.             edge flags -optional 0).  If only three points were entered
  881.             (forming a triangular face), the third and fourth points will
  882.             be the same.  The meanings of the bit-coded "invisible edge
  883.             flags" are shown in the following table.
  884.  
  885.                       Flag bit value           Meaning
  886.                              1        First edge is invisible
  887.                              2        Second edge is invisible
  888.                              4        Third edge is invisible
  889.                              8        Fourth edge is invisible
  890.  
  891.   DIMENSION 2 (name of pseudo-Block containing the current dimension pic-
  892.             ture), 10, 20, 30 (definition point for all dimension types),
  893.             11, 21, 31 (middle point of dimension text), 12, 22, 32
  894.             (insertion point for clones of a dimension (for BASELINE and
  895.             CONTINUE), 70 (Dimension type; 0=rotated, horizontal, or ver-
  896.             tical; 1=aligned; 2=angular; 3=diameter; 4=radius - the value
  897.             128 is added to this field if the dimension text has been
  898.             positioned at a user-defined location rather than at the
  899.             default location), 1 (dimension text explicitly entered by
  900.             the user.  If null, the dimension measurement is drawn as the
  901.             text.  Otherwise, this text is drawn (but if it includes the
  902.             sequence "<>", the dimension measurement is drawn in place of
  903.             the "<>")), 13, 23, 33 (definition point for linear and angu-
  904.             lar dimensions), 14, 24, 34 (definition point for linear and
  905.             angular dimensions), 15, 25, 35 (definition point for diame-
  906.             ter, radius, and angular dimensions), 16, 26, 36 (point
  907.             defining dimension arc for angular dimensions), 40 (leader
  908.             length for radius and diameter dimensions), 50 (angle of
  909.             rotated, horizontal, or vertical linear dimensions).
  910.  
  911.  
  912.  
  913. 16
  914.                                    (C) Drawing Interchange and File Formats
  915.  
  916.             In addition, all dimension types have an optional group (code
  917.             51) that indicates the "horizontal" direction for the Dimen-
  918.             sion entity.  This determines the orientation of dimension
  919.             text and dimension lines for horizontal, vertical and rotated
  920.             linear dimensions.  The group value is the negative of the
  921.             ECS angle of the UCS X axis in effect when the Dimension was
  922.             drawn.  In other words, the X axis of the UCS in effect when
  923.             the Dimension was drawn is always parallel to the XY plane
  924.             for the Dimension's ECS, and the angle between the UCS X axis
  925.             and the ECS X axis is a single 2D angle.  The value in group
  926.             51 is the angle from "horizontal" (the effective X axis) to
  927.             the ECS X axis.  Entity Coordinate Systems (ECS) are
  928.             described later in this section.
  929.  
  930.             For all dimension types, the following groups represent 3D
  931.             WCS points, regardless of the FLATLAND setting.
  932.  
  933.                 10, 20, 30
  934.                 13, 23, 33
  935.                 14, 24, 34
  936.                 15, 25, 35
  937.  
  938.             For all dimension types, the following groups represent ECS
  939.             points, and are 2D or 3D depending on the FLATLAND setting.
  940.  
  941.                 11, 21(, 31)
  942.                 12, 22(, 32)
  943.                 16, 26(, 36)
  944.  
  945.   Linear    (13,23,33)   The point used to specify the first extension line.
  946.             (14,24,34)   The point used to specify the second extension line.
  947.             (10,20,30)   The point used to specify the dimension line.
  948.  
  949.   Angular   (13,23,33) and (14,24,34)  The endpoints of the first line
  950.             (10,20,30) and (15,25,35)  The endpoints of the second line
  951.             (16,26,36)                 The point used to specify the dimen-
  952.                                        sion line arc
  953.  
  954.   Diameter  (15,25,35)   The point used to pick the circle/arc to dimension
  955.             (10,20,30)   The point on that circle directly across from the
  956.                          pick point.
  957.  
  958.   Radius    (15,25,35)   The point used to pick the circle/arc to dimension
  959.             (10,20,30)   The center of that circle.
  960.  
  961.  
  962.  
  963.  
  964.  
  965.  
  966.  
  967.  
  968.  
  969.  
  970.                                                                          17
  971. AutoCAD Reference Manual
  972.  
  973. Entity Coordinate Systems (ECS)
  974.  
  975. To save space in the drawing database (and in the DXF file), the points
  976. associated with each entity are expressed in terms of its own Entity Coor-
  977. dinate System (ECS).  The Entity Coordinate System allows AutoCAD to use a
  978. much more compact means of representation for entities.  With ECS, the only
  979. additional information needed to describe its position in 3D space is the
  980. 3D vector describing the Z axis of the ECS, and the elevation value.
  981.  
  982. For a given Z axis (or extrusion) direction, there is an infinite number of
  983. coordinate systems, defined by translating the origin in 3D space and by
  984. rotating the X and Y axes around the Z axis.  However, for the same Z axis
  985. direction, there is only one Entity Coordinate System.  It has the follow-
  986. ing properties:
  987.  
  988.   o  Its origin coincides with the WCS origin.
  989.   o  The orientation of the X and Y axes within the XY plane are calcu-
  990.      lated in an arbitrary, but consistent manner.  AutoCAD performs
  991.      this calculation using the "arbitrary axis" algorithm described
  992.      below.
  993.  
  994. For some entities, the ECS is equivalent to the World Coordinate System and
  995. all points (DXF groups 10-37) are expressed in World coordinates.  See the
  996. following table.
  997.  
  998.                   Entities                        Notes
  999.         LINE, POINT, 3DFACE, 3D       These entities do not lie in
  1000.         Polyline, 3D Vertex, 3D       a particular plane.  All
  1001.         Mesh, 3D Mesh vertex          points are expressed in
  1002.                                       World coordinates.  Of these
  1003.                                       entities, only Lines and
  1004.                                       Points can be extruded;
  1005.                                       their extrusion direction can
  1006.                                       differ from the World Z axis.
  1007.  
  1008.         CIRCLE, ARC, SOLID, TRACE,    These entities are planar in
  1009.         TEXT, ATTRIB, ATTDEF, SHAPE,  nature.  All points are
  1010.         INSERT, 2D Polyline, 2D       expressed in Entity coordi-
  1011.         Vertex                        nates.  All these entities
  1012.                                       can be extruded; their
  1013.                                       extrusion direction can
  1014.                                       differ from the World Z axis.
  1015.  
  1016.         DIMENSION                     Some of a Dimension's points are
  1017.                                       expressed in WCS, and some in ECS.
  1018.  
  1019.         Others                        The remaining entities have
  1020.                                       no point data and their
  1021.                                       coordinate systems are
  1022.                                       therefore irrelevant.
  1023.  
  1024. Once AutoCAD has established the ECS for a given entity, here's how it
  1025. works:
  1026.  
  1027. 18
  1028.                                    (C) Drawing Interchange and File Formats
  1029.  
  1030.   o  The elevation value stored with an entity indicates how far along
  1031.      the Z axis to shift the XY plane from the WCS origin to make it
  1032.      coincide with the plane that the entity is in.  How much of this
  1033.      is the user-defined elevation is unimportant.
  1034.   o  Any 2D points describing the entity that were entered through the
  1035.      UCS are transformed into the corresponding 2D points in the ECS,
  1036.      which (more often than not) is shifted and rotated with respect to
  1037.      the UCS.
  1038.  
  1039. A few ramifications of this process are:
  1040.  
  1041.   o  You can not reliably find out what UCS was in effect when an
  1042.      entity was acquired.  You can only find out where the entity is in
  1043.      the current UCS if the current UCS has the same Z axis direction
  1044.      as the original UCS (i.e., they both reduce to the same ECS).
  1045.   o  When you enter the XY coordinates of an entity in a given UCS and
  1046.      then do a DXFOUT, you probably won't recognize those XY coordi-
  1047.      nates in the DXF file.  You'll have to know the method by which
  1048.      AutoCAD calculates the X and Y axes in order to work with these
  1049.      values.
  1050.   o  The elevation value stored with an entity and output in DXF files
  1051.      will be a sum of the Z coordinate difference between the UCS XY
  1052.      plane and the ECS XY plane, and the elevation value that the user
  1053.      specified at the time the entity was drawn.
  1054.  
  1055.  
  1056. Arbitrary Axis Algorithm
  1057.  
  1058. The arbitrary axis algorithm is used by AutoCAD internally to implement the
  1059. "arbitrary but consistent" generation of Entity Coordinate Systems for all
  1060. entities except Lines, Points, 3D Faces, and 3D Polylines, which contain
  1061. points in World coordinates.
  1062.  
  1063. Given a unit-length vector to be used as the Z axis of a coordinate system,
  1064. the arbitrary axis algorithm generates a corresponding X axis for the coor-
  1065. dinate system.  The Y axis follows by application of the right hand rule.
  1066.  
  1067. The method is to examine the given Z axis (also called the normal vector)
  1068. and see if it is close to the positive or negative World Z axis.  If it is,
  1069. cross the World Y axis with the given Z axis to arrive at the arbitrary X
  1070. axis.  If not, cross the World Z axis with the given Z axis to arrive at
  1071. the arbitrary X axis.  The boundary at which the decision is made was
  1072. chosen to be both inexpensive to calculate and completely portable across
  1073. machines.  This is achieved by having a sort of "square" polar cap, the
  1074. bounds of which is 1/64, which is precisely specifiable in 6 decimal frac-
  1075. tion digits and in 6 binary fraction bits.
  1076.  
  1077. In mathematical terms, the algorithm does the following (all "vectors" are
  1078. assumed to be in 3D space, specified in the World Coordinate System).
  1079.  
  1080.     Let the given normal vector be called N.
  1081.     Let the World Y axis be called Wy, which is always (0,1,0).
  1082.     Let the World Z axis be called Wz, which is always (0,0,1).
  1083.  
  1084.                                                                          19
  1085. AutoCAD Reference Manual
  1086.  
  1087. We are looking for the arbitrary X and Y axes to go with the normal N.
  1088. They'll be called Ax and Ay.  N could also be called Az (the arbitrary Z
  1089. axis).
  1090.  
  1091.     If (Nx < 1/64) and (Ny < 1/64) then
  1092.        Ax = Wy * N      (where "*" is the cross-product operator).
  1093.     Otherwise,
  1094.        Ax = Wz * N.
  1095.     Scale Ax to unit length.
  1096.  
  1097. The method of getting the Ay vector would be:
  1098.  
  1099.     Ay = N * Ax.
  1100.     Scale Ay to unit length.
  1101.  
  1102.  
  1103. C.1.6  Writing DXF Interface Programs
  1104.  
  1105. Writing a program that communicates with AutoCAD via the DXF mechanism
  1106. often appears far more difficult than it really is.  The DXF file contains
  1107. a seemingly overwhelming amount of information, and examining a DXF file
  1108. manually may lead to the conclusion that the task is hopeless.
  1109.  
  1110. However, the DXF file has been designed to be easy to process by program,
  1111. not manually.  The format was constructed with the deliberate intention of
  1112. making it easy to ignore information you don't care about while easily
  1113. reading the information you need.  Just remember to handle the groups in
  1114. any order and ignore any group you don't care about, and you'll be home
  1115. free.
  1116.  
  1117. As an example, the following is a Microsoft BASIC program that reads a DXF
  1118. file and extracts all the LINE entities from the drawing (ignoring lines
  1119. that appear inside Blocks).  It prints the endpoints of these lines on the
  1120. screen.  As an exercise you might try entering this program into your com-
  1121. puter, running it on a DXF file from one of your drawings, then enhancing
  1122. it to print the center point and radius of any circles it encounters.  This
  1123. program is not put forward as an example of clean programming technique nor
  1124. the way a general DXF processor should be written; it is presented as an
  1125. example of just how simple a DXF-reading program can be.
  1126.  
  1127.     1000 REM
  1128.     1010 REM Extract lines from DXF file
  1129.     1020 REM
  1130.     1030 G1% = 0
  1131.     1040 LINE INPUT "DXF file name: "; A$
  1132.     1050 OPEN "i", 1, A$ + ".dxf"
  1133.     1060 REM
  1134.     1070 REM Ignore until section start encountered
  1135.     1080 REM
  1136.     1090 GOSUB 2000
  1137.     1100 IF G% <> 0 THEN 1090
  1138.     1110 IF S$ <> "SECTION" THEN 1090
  1139.  
  1140.  
  1141. 20
  1142.                                    (C) Drawing Interchange and File Formats
  1143.  
  1144.     1120 GOSUB 2000
  1145.     1130 REM
  1146.     1140 REM Skip unless ENTITIES section
  1147.     1150 REM
  1148.     1160 IF S$ <> "ENTITIES" THEN 1090
  1149.     1170 REM
  1150.     1180 REM Scan until end of section, processing LINEs
  1151.     1190 REM
  1152.     1200 GOSUB 2000
  1153.     1210 IF G% = 0 AND S$ = "ENDSEC" THEN 2200
  1154.     1220 IF G% = 0 AND S$ = "LINE" THEN GOSUB 1400 : GOTO 1210
  1155.     1230 GOTO 1200
  1156.     1400 REM
  1157.     1410 REM Accumulate LINE entity groups
  1158.     1420 REM
  1159.     1430 GOSUB 2000
  1160.     1440 IF G% = 10 THEN X1 = X : Y1 = Y : Z1 = Z
  1161.     1450 IF G% = 11 THEN X2 = X : Y2 = Y : Z2 = Z
  1162.     1460 IF G% = 0 THEN PRINT "Line from (";X1;",";Y1;",";Z1;") to (";X2;
  1163.                               ",";Y2;",";Z2;")
  1164.     1470 GOTO 1430
  1165.     2000 REM
  1166.     2010 REM Read group code and following value
  1167.     2020 REM For X coordinates, read Y and possibly Z also
  1168.     2030 REM
  1169.     2040 IF G1% < 0 THEN G% = -G1% : G1% = 0 ELSE INPUT #1, G%
  1170.     2050 IF G% <   10 OR  G% =  999 THEN LINE INPUT #1, S$ : RETURN
  1171.     2060 IF G% >=  38 AND G% <=  49 THEN INPUT #1, V : RETURN
  1172.     2080 IF G% >=  50 AND G% <=  59 THEN INPUT #1, A : RETURN
  1173.     2090 IF G% >=  60 AND G% <=  69 THEN INPUT #1, P% : RETURN
  1174.     2100 IF G% >=  70 AND G% <=  79 THEN INPUT #1, F% : RETURN
  1175.     2110 IF G% >= 210 AND G% <= 219 THEN 2130
  1176.     2120 IF G% >=  20 THEN PRINT "Invalid group code";G% : STOP
  1177.     2130 INPUT #1, X
  1178.     2140 INPUT #1, G1%
  1179.     2150 IF G1% <> (G%+10) THEN PRINT "Invalid Y coord code";G1% : STOP
  1180.     2160 INPUT #1, Y
  1181.     2170 INPUT #1, G1%
  1182.     2180 IF G1% <> (G%+20) THEN G1% = -G1% ELSE INPUT #1, Z
  1183.     2190 RETURN
  1184.     2200 CLOSE 1
  1185.  
  1186. Writing a program that constructs a DXF file is more difficult, because you
  1187. must maintain consistency within the drawing in order for AutoCAD to find
  1188. it acceptable.  AutoCAD allows you to omit many items in a DXF file and
  1189. still obtain a usable drawing.  The entire HEADER section can be omitted if
  1190. you don't need to set any header variables.  Any of the tables in the
  1191. TABLES section can be omitted if you don't need to make any entries, and in
  1192. fact the entire TABLES section can be dropped if nothing in it is required.
  1193. If you define any linetypes in the LTYPE table, this table must appear
  1194. before the LAYER table.  If no Block Definitions are used in the drawing,
  1195. the BLOCKS section can be omitted.  If present, however, it must appear
  1196. before the ENTITIES section.  Within the ENTITIES section, you can refer-
  1197. ence layer names even though you haven't defined them in the LAYER table.
  1198.  
  1199.                                                                          21
  1200. AutoCAD Reference Manual
  1201.  
  1202. Such layers will be automatically created with color 7 and the CONTINUOUS
  1203. linetype.  The EOF item must be present at the end of file.
  1204.  
  1205. The following Microsoft BASIC program constructs a DXF file representing a
  1206. polygon with a specified number of sides, leftmost origin point, and side
  1207. length.  This program supplies only the ENTITIES section of the DXF file,
  1208. and places all entities generated on the default layer "0".  This may be
  1209. taken as an example of a minimum DXF generation program.  Since this pro-
  1210. gram doesn't create the drawing header, the drawing limits, extents, and
  1211. current view will be invalid after performing a DXFIN on the drawing gener-
  1212. ated by this program.  You can do a "ZOOM E" to fill the screen with the
  1213. drawing generated.  Then adjust the limits manually.
  1214.  
  1215.     1000 REM
  1216.     1010 REM Polygon generator
  1217.     1020 REM
  1218.     1030 LINE INPUT "Drawing (DXF) file name: "; A$
  1219.     1040 OPEN "o", 1, A$ + ".dxf"
  1220.     1050 PRINT #1, 0
  1221.     1060 PRINT #1, "SECTION"
  1222.     1070 PRINT #1, 2
  1223.     1080 PRINT #1, "ENTITIES"
  1224.     1090 PI = ATN(1) * 4
  1225.     1100 INPUT "Number of sides for polygon: "; S%
  1226.     1110 INPUT "Starting point (X,Y): "; X, Y
  1227.     1120 INPUT "Polygon side: "; D
  1228.     1130 A1 = (2 * PI) / S%
  1229.     1140 A = PI / 2
  1230.     1150 FOR I% = 1 TO S%
  1231.     1160 PRINT #1, 0
  1232.     1170 PRINT #1, "LINE"
  1233.     1180 PRINT #1, 8
  1234.     1190 PRINT #1, "0"
  1235.     1200 PRINT #1, 10
  1236.     1210 PRINT #1, X
  1237.     1220 PRINT #1, 20
  1238.     1230 PRINT #1, Y
  1239.     1240 PRINT #1, 30
  1240.     1250 PRINT #1, 0.0
  1241.     1260 NX = D * COS(A) + X
  1242.     1270 NY = D * SIN(A) + Y
  1243.     1280 PRINT #1, 11
  1244.     1290 PRINT #1, NX
  1245.     1300 PRINT #1, 21
  1246.     1310 PRINT #1, NY
  1247.     1320 PRINT #1, 31
  1248.     1330 PRINT #1, 0.0
  1249.     1340 X = NX
  1250.     1350 Y = NY
  1251.     1360 A = A + A1
  1252.     1370 NEXT I%
  1253.     1380 PRINT #1, 0
  1254.     1390 PRINT #1, "ENDSEC"
  1255.  
  1256. 22
  1257.                                    (C) Drawing Interchange and File Formats
  1258.  
  1259.     1400 PRINT #1, 0
  1260.     1410 PRINT #1, "EOF"
  1261.     1420 CLOSE 1
  1262.  
  1263. The DXFIN command is relatively forgiving with respect to the format of
  1264. data items.  As long as a properly formatted item appears on the line on
  1265. which the data is expected, DXFIN will accept it (of course, string items
  1266. should not have leading spaces unless these are intended to be part of the
  1267. string).  The above program takes advantage of this flexibility in input
  1268. format, and does not go to great effort to generate a file appearing
  1269. exactly like one generated by AutoCAD.
  1270.  
  1271. In the case of error loading a DXF file using DXFIN, AutoCAD reports the
  1272. error with a message indicating the nature of the error detected and the
  1273. last line processed in the DXF file before the error was detected.  This
  1274. may not be the line on which the error occurred, especially in the case of
  1275. such errors as omission of required groups.
  1276.  
  1277.  
  1278.  
  1279. C.2  Binary Drawing Interchange Files
  1280.  
  1281. The ASCII DXF file format described in the preceding sections of this
  1282. appendix is a complete representation of an AutoCAD drawing in an ASCII
  1283. text form easily processed by other programs.  In addition, AutoCAD can
  1284. produce or read a binary form of the full DXF file, and accepts limited
  1285. input in another binary file format.  These binary files are described in
  1286. the following sections.
  1287.  
  1288.  
  1289. C.2.1  Binary DXF Files
  1290.  
  1291. The DXFOUT command provides a "Binary" option that writes binary DXF files.
  1292. Such a file contains all of the information present in an ASCII DXF file,
  1293. but in a much more compact form that takes, typically, 25% less file space
  1294. and can be read and written more quickly (typically 5 times faster) by
  1295. AutoCAD.  Unlike ASCII DXF files, which entail a trade-off between size and
  1296. floating-point accuracy, binary DXF files preserve all of the accuracy in
  1297. the drawing database.  AutoCAD Release 10 is the first version to support
  1298. this form of DXF file; it cannot be read by older versions.
  1299.  
  1300. A binary DXF file begins with a 22-byte sentinel consisting of:
  1301.  
  1302.     "AutoCAD Binary DXF<CR><LF><SUB><NUL>"
  1303.  
  1304. Following the sentinel are (group,value) pairs as in an ASCII DXF file, but
  1305. represented in binary form.  The group code is a single-byte binary value,
  1306. and the value that follows is one of the following:
  1307.  
  1308.   o  a two-byte integer with the least significant byte first and the
  1309.      most significant byte last,
  1310.  
  1311.  
  1312.  
  1313.                                                                          23
  1314. AutoCAD Reference Manual
  1315.  
  1316.   o  an eight-byte IEEE double precision floating-point number stored
  1317.      with the least significant byte first and the most significant
  1318.      byte last, or
  1319.  
  1320.   o  an ASCII string terminated by a zero (NUL) byte.
  1321.  
  1322. The type of the datum following a group is determined from the group code
  1323. according to the same rules used in decoding ASCII DXF files.  Translation
  1324. of angles to degrees, and dates to fractional Julian date representation,
  1325. is performed for binary files as well as for ASCII DXF files.  The comment
  1326. group, 999, is not used in binary DXF files.
  1327.  
  1328. DXFOUT writes binary DXF files with the same file type (".dxf") as for
  1329. ASCII DXF files.  The DXFIN command automatically recognizes a binary file
  1330. (by means of its sentinel string) and loads it.  There is no need for you
  1331. to identify it as a binary file.
  1332.  
  1333. If DXFIN encounters an error in a binary DXF file, it reports the byte
  1334. address within the file where the error was detected.
  1335.  
  1336.  
  1337. C.3  Binary Drawing Interchange (DXB) Files
  1338.  
  1339. The DXF file formats described earlier in this appendix are complete repre-
  1340. sentations of an AutoCAD drawing that can be written and read by AutoCAD
  1341. and other programs.  However, AutoShade(tm) and programs executed via the
  1342. "external commands" facility (Appendix B) often have a need to supply
  1343. simple geometric input to AutoCAD.  For these purposes, another file format
  1344. even more compact than the binary DXF format is supported.  This format,
  1345. called DXB (for "drawing interchange binary") is limited in the entities it
  1346. can represent.  Furthermore, AutoCAD has a command to read such files, but
  1347. no direct method of writing them.  (The ADI plotter driver can plot to a
  1348. file in DXB format.)
  1349.  
  1350.  
  1351. C.3.1  DXBIN Command
  1352.  
  1353. To load a DXB file produced by a program such as AutoShade, enter the DXBIN
  1354. command:
  1355.  
  1356.     Command:  DXBIN
  1357.     DXB file:
  1358.  
  1359. enter the name of the file you wish to load.  Don't include a file type;
  1360. ".dxb" is assumed.
  1361.  
  1362.  
  1363.  
  1364.  
  1365.  
  1366.  
  1367.  
  1368.  
  1369.  
  1370. 24
  1371.                                    (C) Drawing Interchange and File Formats
  1372.  
  1373. C.3.2  DXB File Format
  1374.  
  1375. This information is for experienced programmers, and is subject to change
  1376. without notice.
  1377.  
  1378. The format of a DXB file is as follows:
  1379.  
  1380.     Header:      "AutoCAD DXB 1.0" CR LF ^Z NUL       (19 bytes)
  1381.     Data:      . . . Zero or more data records . . .
  1382.     Terminator:  NUL                                  (1 byte)
  1383.  
  1384. Each data record begins with a single byte giving its type, followed by
  1385. data items.  The data items have various forms of representation and encod-
  1386. ing.  In the descriptions below, each data item is prefixed with a letter
  1387. and a hyphen.  The meaning of the letter codes is as follows:
  1388.  
  1389.   w-  16-bit integer, byte reversed in the standard 8086 style (least
  1390.       significant byte first, most significant byte second).
  1391.  
  1392.   f-  IEEE 64-bit floating-point value stored with lsb first, msb last
  1393.       (as stored by an 8087).
  1394.  
  1395.   l-  32-bit integer with the bytes reversed 8086-style.
  1396.  
  1397.   n-  Number which may be either a 16-bit integer or a floating-point
  1398.       number depending on the most recent setting of the "number mode"
  1399.       data item.  The number mode defaults to 0, signifying integers.  If
  1400.       set to 1, all n- items will be read as floating-point.
  1401.  
  1402.   u-  Item which is either a 32-bit integer or a floating-point number
  1403.       depending on the most recent number mode setting.  If a 32-bit
  1404.       integer, the value is scaled by multiplying it by 65536 (2^16).  If
  1405.       a floating-point value, no scaling is applied.
  1406.  
  1407.   a-  Item representing an angle.  If number mode is integer, this is a
  1408.       32-bit integer representing an angle in units of millionths of a
  1409.       degree (range 0 to 360,000,000).  If a floating-point number, rep-
  1410.       resents degrees.
  1411.  
  1412. In the following table, the lengths include the item-type byte and assume
  1413. the number mode is set to zero (integer mode).  If number mode is floating-
  1414. point, add 6 bytes to the length for each n- item present and 4 bytes for
  1415. each a-, or u- item present.
  1416.  
  1417.         Item type        Code           Data items           Length
  1418.                        (decimal)                             (bytes)
  1419.      LINE                  1      n-fromx n-fromy               9
  1420.                                   n-tox n-toy
  1421.      POINT                 2      n-x n-y                       5
  1422.      CIRCLE                3      n-ctrx n-ctry n-rad           7
  1423.      ARC                   8      n-ctrx n-ctry n-rad          19
  1424.                                   a-starta a-enda
  1425.                                                       continued ...
  1426.  
  1427.                                                                          25
  1428. AutoCAD Reference Manual
  1429.  
  1430.         Item type        Code           Data items           Length
  1431.                        (decimal)                             (bytes)
  1432.      TRACE                 9      n-x1 n-y1 n-x2 n-y2          17
  1433.                                   n-x3 n-y3 n-x4 n-y4
  1434.      SOLID                11      n-x1 n-y1 n-x2 n-y2          17
  1435.                                   n-x3 n-y3 n-x4 n-y4
  1436.      SEQEND               17      (none)                        1
  1437.      POLYLINE             19      w-closureflag                 3
  1438.      VERTEX               20      n-x n-y                       5
  1439.      3DLINE               21      n-fromx n-fromy n-fromz      13
  1440.                                   n-tox n-toy n-toz
  1441.      3DFACE               22      n-x1 n-y1 n-z1               25
  1442.                                   n-x2 n-y2 n-x2
  1443.                                   n-x3 n-y3 n-z3
  1444.                                   n-x4 n-y4 n-z4
  1445.      SCALE FACTOR         128     f-scalefac                    9
  1446.      NEW LAYER            129     "layername" NUL          "layername"
  1447.                                                            length + 2
  1448.      LINE EXTENSION       130     n-tox n-toy                   5
  1449.      TRACE EXTENSION      131     n-x3 n-y3 n-x4 n-y4           9
  1450.      BLOCK BASE           132     n-bx n-by                     5
  1451.      BULGE                133     u-2h/d                        5
  1452.      WIDTH                134     n-startw n-endw               5
  1453.      NUMBER MODE          135     w-mode                        3
  1454.      NEW COLOR            136     w-colornum                    3
  1455.      3DLINE EXTENSION     137     n-tox n-toy n-toz             7
  1456.  
  1457. The LINE EXTENSION item extends the last line or line extension from its
  1458. "to" point to a new "to point".  The trace extension item similarly extends
  1459. the last trace solid, or trace extension from its x3,y3-x4,y4 ending line
  1460. to a new x3,y3-x4,y4 line.
  1461.  
  1462. The SCALE FACTOR is a floating-point value by which all integer coordinates
  1463. are multiplied to obtain the floating-point coordinates used by the actual
  1464. entities.  The initial scale factor when a file is read is 1.0.  The NEW
  1465. LAYER item will create a layer if none exists, giving it the same defaults
  1466. as the "LAYER NEW" command, and will set that layer as the current layer
  1467. for subsequent entities.  At the end of the DXB file load, the layer in
  1468. effect before the command will be restored.
  1469.  
  1470. The BLOCK BASE item specifies the base (origin) point of a Block being cre-
  1471. ated.  The Block base must be defined before the first entity record is
  1472. encountered.  If DXB is not defining a Block, this specification will be
  1473. ignored.
  1474.  
  1475. A Polyline consists of straight segments of fixed width connecting the ver-
  1476. tices, except as overridden by the BULGE and WIDTH items described below.
  1477. The closure flag should be 0 or 1; if it is 1, then there is an implicit
  1478. segment from the last vertex (immediately before the SEQEND) to the first
  1479. vertex.
  1480.  
  1481. A BULGE item, encountered between two VERTEX items (or after the last
  1482. VERTEX of a closed Polyline), indicates that the two vertices are connected
  1483.  
  1484. 26
  1485.                                    (C) Drawing Interchange and File Formats
  1486.  
  1487. by an arc rather than a straight segment.  If the line segment connecting
  1488. the vertices would have length d, and the perpendicular distance from the
  1489. midpoint of that segment to the arc is h, then the magnitude of the BULGE
  1490. is (2 * h / d).  The sign is negative if the arc from the first vertex to
  1491. the second is clockwise.  A semicircle thus has a bulge of 1 (or -1).  If
  1492. the number mode is 0 (integer), BULGE items are scaled by 216.  If the
  1493. number mode has been set to floating-point, then the floating-point value
  1494. supplied is just 2*h/d (not scaled).
  1495.  
  1496. The WIDTH item indicates the starting and ending widths of the segment
  1497. (straight or curved) connecting two vertices.  This width stays in effect
  1498. until the next width item or the SEQEND.  If there is a WIDTH item between
  1499. the POLYLINE item and the first VERTEX, it is stored as a default width for
  1500. the Polyline; this will save considerable database space if the Polyline
  1501. has several segments of this width.
  1502.  
  1503. The NUMBER MODE item controls the mode of items with types given in the
  1504. table above as n-, a-, or u-.  If the value supplied is zero, these values
  1505. will be integers, otherwise floating-point.  The storage and implicit scal-
  1506. ing conventions for these values in both modes are described above.
  1507.  
  1508. LINEs and 3DLINEs share the same cells to remember the last to-point, so
  1509. you shouldn't mix extension groups for the two entities without an initial
  1510. group before the extension.  There is no "extension" group for 3DFACEs, as
  1511. there's no obvious edge to extend from.
  1512.  
  1513. The "NEW COLOR" group specifies the color for subsequent entities in the
  1514. DXB file.  The "w-colornum" word argument is in the range from 0 to 256.  0
  1515. means color by block, 1-255 are the standard AutoCAD colors, and 256 means
  1516. color by layer.  A color outside the range from 0 to 256 sets the color
  1517. back to the current entity color (you can do this deliberately, and it can
  1518. be quite handy).  The initial entity color of material added by DXBIN is
  1519. the current entity color.
  1520.  
  1521. All points specified in the DXB file are interpreted in terms of the cur-
  1522. rent UCS at the time the DXBIN command is executed.
  1523.  
  1524.  
  1525. C.3.3  Writing DXB Files
  1526.  
  1527. There is no direct AutoCAD command to write a DXB file, but the special
  1528. "ADI" plotter driver can write such a file.  If you want to create a DXB
  1529. file from an AutoCAD drawing, configure the "ADI" plotter and select its
  1530. DXB file output option.
  1531.  
  1532.  
  1533.  
  1534.  
  1535.  
  1536.  
  1537.  
  1538.  
  1539.  
  1540.  
  1541.                                                                          27
  1542. AutoCAD Reference Manual
  1543.  
  1544. C.4  Initial Graphics Exchange Standard (IGES) Files
  1545.  
  1546. Using the commands described in this section, you can instruct AutoCAD to
  1547. read and write IGES format interchange files.
  1548.  
  1549. NOTE:  The format of IGES files and the mapping performed to translate
  1550. between AutoCAD drawing information and IGES are described in the separate
  1551. AutoCAD / IGES Interface Specifications document (one of the items supplied
  1552. when you return your AutoCAD license registration card).
  1553.  
  1554.  
  1555. C.4.1  IGESOUT Command
  1556.  
  1557. You can generate an Initial Graphics Exchange Standard (IGES) interchange
  1558. file from an existing AutoCAD drawing by means of the Drawing Editor's
  1559. IGESOUT command.  The command format is:
  1560.  
  1561.     Command:  IGESOUT   File name:  (name or RETURN)
  1562.  
  1563. The default name for the output file is the same as that of the current
  1564. drawing, but with a file type of ".igs".  If you specify an explicit file
  1565. name without including a file type, ".igs" is assumed. If a file with the
  1566. same name already exists, it is deleted.
  1567.  
  1568.  
  1569. C.4.2  IGESIN Command
  1570.  
  1571. An IGES interchange file can be converted into an AutoCAD drawing by means
  1572. of the IGESIN command.  First enter the Drawing Editor using the "Create
  1573. new drawing" task from the Main Menu.  Then issue the IGESIN command.
  1574.  
  1575.     Command:  IGESIN   File name:  (name)
  1576.  
  1577. Enter the name of the IGES file to be loaded.
  1578.  
  1579. If a serious error is encountered, the input process is halted and an error
  1580. message is displayed reporting where the error was found.  The partial
  1581. drawing is not discarded.
  1582.  
  1583.  
  1584.  
  1585.  
  1586.  
  1587.  
  1588.  
  1589.  
  1590.  
  1591.  
  1592.  
  1593.  
  1594.  
  1595.  
  1596.  
  1597.  
  1598. 28
  1599.                                    (C) Drawing Interchange and File Formats
  1600.  
  1601. C.5  Slide File Format
  1602.  
  1603. AutoCAD slide files are screen images written by the MSLIDE command and
  1604. read by the VSLIDE command.  This section describes the format of slide
  1605. files, for the benefit of developers who wish to incorporate support for
  1606. AutoCAD slides into their programs.
  1607.  
  1608. This information is for experienced programmers, and is subject to change
  1609. without notice.
  1610.  
  1611. The general format of a slide file is:
  1612.  
  1613.    1.  Header (31 bytes)
  1614.    2.  One or more data records (variable length)
  1615.  
  1616. All coordinates and sizes written to the slide file reflect the graphics
  1617. area of the display device from which the slide was created, with point
  1618. (0,0) located at the lower left corner of the graphics area.  For AutoCAD
  1619. Release 9 and later, the slide file header consists of the following
  1620. fields:
  1621.  
  1622.       Field       Bytes                     Description
  1623.  Id string          17   "AutoCAD Slide" CR LF ^Z NUL
  1624.  
  1625.  Type indicator     1    Currently set to 86 (decimal).
  1626.  
  1627.  Level indicator    1    Currently set to 2.
  1628.  
  1629.  High X dot         2    Width of the graphics area - 1, in pixels.
  1630.  
  1631.  High Y dot         2    Height of the graphics area - 1, in pixels.
  1632.  
  1633.  Aspect ratio       4    Aspect ratio (horizontal size / vertical size in
  1634.                          inches) of the graphics area, scaled by
  1635.                          10,000,000.  This value is always written with
  1636.                          the least significant byte first.
  1637.  
  1638.  Hardware fill      2    Either 0 or 2 (value is unimportant).
  1639.  
  1640.  Test number        2    A number (1234 hex) used to determine whether
  1641.                          all 2-byte values in this slide file were writ-
  1642.                          ten with the high byte first (as by Intel
  1643.                          8086-family CPUs) or the low byte first (as by
  1644.                          Motorola 68000-family CPUs).
  1645.  
  1646. Data records follow the header.  Each data record begins with a 2-byte
  1647. field whose high-order byte is the record type.  The remainder of the
  1648. record may be composed of 1-byte or 2-byte fields, as described in the fol-
  1649. lowing table.  To determine whether the 2-byte fields are written with the
  1650. high byte first or the low byte first, examine the Test number field of the
  1651. header, described above.
  1652.  
  1653.  
  1654.  
  1655.                                                                          29
  1656. AutoCAD Reference Manual
  1657.  
  1658.      Record    Length      Meaning                Description
  1659.    type (hex)  (bytes)
  1660.     00 - 7F       8        Vector      The from-X coordinate for an
  1661.                                        ordinary vector.  From-Y, to-X,
  1662.                                        and to-Y follow in that order, as
  1663.                                        2-byte values.  The from point is
  1664.                                        saved as the last point.
  1665.     80 - FA       -       Undefined    Reserved for future use.
  1666.        FB         5     Offset vector  The low-order byte and the fol-
  1667.                                        lowing three bytes specify the
  1668.                                        endpoints (from-X, from-Y, to-X,
  1669.                                        to-Y) of a vector, in terms of
  1670.                                        offsets (-128 to +127) from the
  1671.                                        saved last point.  The adjusted
  1672.                                        from point is saved as the last
  1673.                                        point for use by subsequent vec-
  1674.                                        tors.
  1675.        FC         2      End of file   The low-order byte is 00.
  1676.        FD         6      Solid fill    The low-order byte is always
  1677.                                        zero.  The following two 2-byte
  1678.                                        values specify the X and Y coor-
  1679.                                        dinates of one vertex of a poly-
  1680.                                        gon to be solid-filled.  3 to 10
  1681.                                        such records occur in sequence.
  1682.                                        A Solid fill record with a nega-
  1683.                                        tive Y coordinate indicates the
  1684.                                        start or end of such a flood
  1685.                                        sequence.  In the start record,
  1686.                                        the X coordinate indicates the
  1687.                                        number of vertex records to
  1688.                                        follow.
  1689.        FE         3        Common      This is a vector starting at the
  1690.                           endpoint     last point.  The low-order byte
  1691.                            vector      and the following byte specify
  1692.                                        to-X and to-Y in terms of offsets
  1693.                                        (-128 to +127) from the saved
  1694.                                        last point.  The adjusted to
  1695.                                        point is saved as the last point
  1696.                                        for use by subsequent vectors.
  1697.        FF         2       New color    Subsequent vectors are to be
  1698.                                        drawn using the color number
  1699.                                        indicated by the low-order byte.
  1700.  
  1701. If a slide contains any vectors at all, a New color record will be the
  1702. first data record.  The order of the vectors in a slide, and the order of
  1703. the endpoints of those vectors, may vary.
  1704.  
  1705. For example, the following is an annotated hex dump of a simple slide file
  1706. created on an IBM PC/AT with an IBM Enhanced Graphics Adapter.  The slide
  1707. consists of a white diagonal line from the lower left corner to the upper
  1708. right corner of the graphics area, a green vertical line near the lower
  1709. left corner, and a small red rectangle at the lower left corner.
  1710.  
  1711.  
  1712. 30
  1713.                                    (C) Drawing Interchange and File Formats
  1714.  
  1715.   41 75 74 6F 43 41        Id string ("AutoCAD Slide" CR LF ^Z NUL)
  1716.   44 20 53 6C 69 64
  1717.   65 0D 0A 1A 00
  1718.   56                       Type indicator (86)
  1719.   02                       Level indicator (2)
  1720.   3C 02                    High X dot (572)
  1721.   24 01                    High Y dot (292)
  1722.   0B 80 DF 00              Aspect ratio (14,647,307 / 10,000,000 = 1.46)
  1723.   02 00                    Hardware fill (2)
  1724.   34 12                    Test number (1234 hex)
  1725.   07 FF                    New color (7 = white)
  1726.   3C 02 24 01 00 00 00 00  Vector from 572,292 to 0,0.  572,292 becomes
  1727.                            "last" point
  1728.   03 FF                    New color (3 = green)
  1729.   0F 00 32 00 0F 00 13 00  Vector from 15,50 to 15,19.  15,50 becomes
  1730.                            "last" point
  1731.   01 FF                    New color (1 = red)
  1732.   12 FB E7 12 CE           Offset vector from 15+18,50-25 (33,25) to
  1733.                            15+18,50-50 (33,0).  33,25 becomes "last" point
  1734.   DF FE 00                 Common-endpoint vector from 33,25 to
  1735.                            33-33,25+0 (0,25).  0,25 becomes "last" point
  1736.   00 FE E7                 Common-endpoint vector from (0,25) to
  1737.                            0+0,25-25 (0,0).  0,0 becomes "last" point
  1738.   21 FE 00                 Common-endpoint vector from (0,0) to
  1739.                            0+33,0+0 (33,0).  33,0 becomes "last" point
  1740.   00 FC                    End of file
  1741.  
  1742.  
  1743. Old Slide Header
  1744.  
  1745. The slide format described above is that produced by AutoCAD Release 9 and
  1746. later, and is portable among all computers running AutoCAD Release 9 or
  1747. later.  Previous versions of AutoCAD (as well as AutoShade 1.0 and
  1748. AutoSketch 1.02) produce slides with a somewhat different header, as shown
  1749. below.
  1750.  
  1751.       Field       Bytes                     Description
  1752.  Id string          17   "AutoCAD Slide" CR LF ^Z NUL
  1753.  Type indicator     1    86 (decimal).
  1754.  Level indicator    1    1 (old format).
  1755.  High X dot         2    Width of the graphics area - 1, in pixels.
  1756.  High Y dot         2    Height of the graphics area - 1, in pixels.
  1757.  Aspect ratio       8    Aspect ratio (horizontal size / vertical size in
  1758.                          inches) of the graphics area, written as a
  1759.                          floating-point number.
  1760.  Hardware fill      2    Either 0 or 2 (value is unimportant).
  1761.  Filler byte        1    Unused
  1762.  
  1763. Note that the old-format header does not contain a Test number field.  The
  1764. floating-point aspect ratio value and all two-byte integers are written in
  1765. the native format of the CPU used to create the file (for 8086-family CPUs,
  1766. IEEE double-precision and low byte first).  Old-format slide files are not
  1767. portable across machine types, but they can be read by any version of AutoCAD
  1768. running on the same CPU type as the CPU with which the slide was created.
  1769.  
  1770.                                                                          31
  1771. AutoCAD Reference Manual
  1772.  
  1773. C.6  Slide Library File Format
  1774.  
  1775. This section describes the format of AutoCAD slide libraries (Release 9 and
  1776. later), for the benefit of developers who wish to incorporate support for
  1777. slide libraries into their programs.
  1778.  
  1779. This information is for experienced programmers, and is subject to change
  1780. without notice.
  1781.  
  1782. The general format of a slide library is:
  1783.  
  1784.   1.  Header (32 bytes)
  1785.       "AutoCAD Slide Library 1.0" CR LF ^Z NUL NUL NUL NUL
  1786.   2.  One or more slide directory entries (36 bytes each)
  1787.   3.  One or more slides (variable length)
  1788.  
  1789. Slide directory entries have the following format:
  1790.  
  1791.   1.  Slide name (NUL terminated) (32 bytes)
  1792.   2.  Address of slide within library file (4 bytes)
  1793.  
  1794. The slide address is always written with the low byte first.  Each slide to
  1795. which the directory points is a complete slide file as described in the
  1796. previous section.  The end of the slide directory is signified by an entry
  1797. with a null slide name (first byte is NUL).  A slide library may contain a
  1798. mixture of old-format and new-format slides.
  1799.  
  1800.  
  1801. <end of document>
  1802.  
  1803.  
  1804.  
  1805.  
  1806.  
  1807.  
  1808.  
  1809.  
  1810.  
  1811.  
  1812.  
  1813.  
  1814.  
  1815.  
  1816.  
  1817.  
  1818.  
  1819.  
  1820.  
  1821.  
  1822.  
  1823.  
  1824.  
  1825.  
  1826. 32
  1827.  
  1828. dxf/dxf.doc: 1825 lines
  1829. (continue editing letter)
  1830. /* AutoCAD DXF file to DKB Data File Converter */
  1831. /* Version 1.0 By Aaron A. Collins.  Written 8/13/90 */
  1832. /* This program is released to the public domain. */
  1833.  
  1834. #include <stdio.h>
  1835. #include <stdlib.h>
  1836. #include <string.h>
  1837.  
  1838. #define BUFSIZE    2048
  1839. #define FABS(x) ((x<0.0)?-x:x)
  1840.  
  1841. int getline (void);
  1842. void writeobj (void);
  1843. void finishobj (int color);
  1844. void lookupcolor (int color, float *red, float *green, float *blue);
  1845. int checkdegen(int a, int b, int c);
  1846.  
  1847. int groupcode;
  1848. char inname[80], outname[80];
  1849. char linbuf[BUFSIZE];
  1850. FILE *infile, *outfile;
  1851. long primitives = 0L, degenerates = 0L;
  1852. char curobj[80];
  1853. int curcolor;
  1854. float curthick;
  1855. float xcoords[10];
  1856. float ycoords[10];
  1857. float zcoords[10];
  1858. float floats[10];
  1859. float angles[10];
  1860. int ints[10];
  1861. float max_x, max_y, max_z, min_x, min_y, min_z;
  1862.  
  1863. main(argc, argv)
  1864. int argc;
  1865. char *argv[];
  1866. {
  1867.     char *index;
  1868.  
  1869.     printf("\n\nAutoCad DXF to DKB .Data file Translator\n");
  1870.     printf("Version 1.0 Written By Aaron A. Collins, 8/13/90\n");
  1871.     printf("This program is released to the public domain.\n\n");
  1872.     if (argc < 2 || argc > 3)
  1873.     {
  1874.         printf("Usage:  %s infile[.DXF] [outfile[.DAT]]\n", argv[0]);
  1875.         exit(1);
  1876.     }
  1877.     strcpy(inname, argv[1]);    /* make copy we can mess with */
  1878.     if (!strchr(inname, '.'))    /* no dot present in filename? */
  1879.         strcat(inname, ".DXF");
  1880.     if (!(infile = fopen(inname, "r")))
  1881.     {
  1882.         printf("Cannot open input file %s!\n", inname);
  1883.         exit(1);
  1884.     }
  1885.     if (argc < 3)            /* i.e. no 2nd name supplied... */
  1886.     {
  1887.         strcpy(outname, inname);
  1888.         index = strchr(outname, '.');    /* find the dot */
  1889.         strcpy(index, ".DAT");        /* make new ext. .DAT... */
  1890.     }
  1891.     else
  1892.     {
  1893.         strcpy(outname, argv[2]);
  1894.         if (!strchr(inname, '.'))    /* no dot in filename? */
  1895.             strcat(inname, ".DAT");    /* add .DAT extension */
  1896.     }
  1897.     if (!(outfile = fopen(outname, "w")))
  1898.     {
  1899.         printf("Cannot create output file %s!\n", outname);
  1900.         fclose(infile);
  1901.         exit(1);
  1902.     }
  1903.  
  1904.     printf("\nPlease wait; Processing...");
  1905.     
  1906.     fprintf(outfile, "{ %s: Converted from AutoCad DXF File: %s }\n\n", outname,  
  1907. inname);
  1908.     fprintf(outfile, "INCLUDE \"basicshapes.data\"\n\n");
  1909.     fprintf(outfile, "{ Put a VIEW_POINT here... }\n\n");
  1910.     fprintf(outfile, "{ Put a LIGHT_SOURCE here... }\n\n");
  1911.     fprintf(outfile, "COMPOSITE\n");
  1912.  
  1913.     curobj[0] = '\0';    /* not working on any object currently */
  1914.     curcolor = 7;        /* and it also doesn't have a color yet... */
  1915.     max_x = max_y = max_z = -10000000.0;    /* init bounding limits */
  1916.     min_x = min_y = min_z =  10000000.0;
  1917.  
  1918. find:    while (!feof(infile))    /* run file up to the "ENTITIES" section */
  1919.     {
  1920.         if (getline())        /* get a group code and a line */
  1921.             goto stopit;
  1922.         if (groupcode == 0)    /* file section mark */
  1923.         {
  1924.             if (strstr(linbuf, "EOF"))
  1925.                 goto stopit;
  1926.             if (strstr(linbuf, "SECTION"))
  1927.             {
  1928.                 if (getline())
  1929.                     goto stopit;
  1930.                 if (groupcode != 2)
  1931.                     continue;
  1932.                 if (strstr(linbuf, "ENTITIES"))
  1933.                     break;
  1934.             }
  1935.         }
  1936.     }
  1937.     while (!feof(infile))        /* scan ENTITIES section */
  1938.     {
  1939.         if (getline())        /* get a group code and a line */
  1940.             break;
  1941.         if (groupcode < 10)    /* cardinal group codes */
  1942.         {
  1943.             switch(groupcode)
  1944.             {
  1945.                 case 0: /* start of entity, table, file sep */
  1946.                     if (strstr(linbuf, "EOF"))
  1947.                     {
  1948.                         writeobj(); /* dump object */
  1949.                         goto stopit;
  1950.                     }
  1951.                     if (strstr(linbuf, "ENDSEC"))
  1952.                     {
  1953.                         writeobj(); /* dump object */
  1954.                         goto find;
  1955.                     }
  1956.                     writeobj();    /* dump old object */
  1957.                     curobj[0] = '\0'; /* reset object */
  1958.                     curcolor = 7;
  1959.                     strcpy(curobj, linbuf);    /* get new */
  1960.                     break;
  1961.                 case 1:    /* primary text value for entity (?)*/
  1962.                     break;
  1963.                 case 2: /* block name, attribute tag, etc */
  1964.                 case 3:    /* other names */
  1965.                 case 4:
  1966.                     break;
  1967.                 case 5:    /* entity handle (hex string) */
  1968.                     break;
  1969.                 case 6: /* line type name */
  1970.                     break;
  1971.                 case 7: /* text style name */
  1972.                     break;
  1973.                 case 8: /* layer name */
  1974.                     break;
  1975.                 case 9: /* variable name ID (only in header)*/
  1976.                     break;
  1977.             }
  1978.         }
  1979.         else if (groupcode >= 10 && groupcode < 19) /* Some X coord */
  1980.         {
  1981.             sscanf(linbuf, "%f", &(xcoords[groupcode-10]));
  1982.             if (xcoords[groupcode-10] > max_x)
  1983.                 max_x = xcoords[groupcode-10];
  1984.             if (xcoords[groupcode-10] < min_x)
  1985.                 min_x = xcoords[groupcode-10];
  1986.         }
  1987.         else if (groupcode >= 20 && groupcode < 29) /* Some Y coord */
  1988.         {
  1989.             sscanf(linbuf, "%f", &(ycoords[groupcode-20]));
  1990.             if (ycoords[groupcode-20] > max_y)
  1991.                 max_y = ycoords[groupcode-20];
  1992.             if (ycoords[groupcode-20] < min_y)
  1993.                 min_y = ycoords[groupcode-20];
  1994.         }
  1995.         else if (groupcode >= 30 && groupcode < 38) /* Some Z coord */
  1996.         {
  1997.             sscanf(linbuf, "%f", &(zcoords[groupcode-30]));
  1998.             if (zcoords[groupcode-30] > max_z)
  1999.                 max_z = zcoords[groupcode-30];
  2000.             if (zcoords[groupcode-30] < min_z)
  2001.                 min_z = zcoords[groupcode-30];
  2002.         }
  2003.         else if (groupcode == 38) /* entity elevation if nonzero */
  2004.         {
  2005.         }
  2006.         else if (groupcode == 39) /* entity thickness if nonzero */
  2007.         {
  2008.         }
  2009.         else if (groupcode >= 40 && groupcode < 49) /* misc floats */
  2010.         {
  2011.             sscanf(linbuf, "%f", &(floats[groupcode-40]));
  2012.         }
  2013.         else if (groupcode == 49) /* repeated value groups */
  2014.         {
  2015.         }
  2016.         else if (groupcode >= 50 && groupcode < 59) /* misc angles */
  2017.         {
  2018.             sscanf(linbuf, "%f", &(angles[groupcode-50]));
  2019.         }
  2020.         else if (groupcode == 62) /* Color number */
  2021.         {
  2022.             sscanf(linbuf, "%6d", &curcolor);
  2023.         }
  2024.         else if (groupcode == 66) /* "entities follow" flag */
  2025.         {
  2026.         }
  2027.         else if (groupcode >= 70 && groupcode < 79) /* misc ints */
  2028.         {
  2029.             sscanf(linbuf, "%f", &(ints[groupcode-70]));
  2030.         }
  2031.         else if (groupcode == 210 || groupcode == 220 || groupcode == 230)
  2032.         {    /* X, Y, Z components of extrusion direction */
  2033.         }
  2034.     }
  2035. stopit: fprintf(outfile, "  BOUNDED_BY\n    INTERSECTION\n");
  2036.     fprintf(outfile, "      PLANE <1.0  0.0  0.0> %1.04f END_PLANE\n",  
  2037. FABS(max_x) * 1.01);
  2038.     fprintf(outfile, "      PLANE <-1.0 0.0  0.0> %1.04f END_PLANE\n",  
  2039. FABS(min_x) * 1.01);
  2040.     fprintf(outfile, "      PLANE <0.0  1.0  0.0> %1.04f END_PLANE\n",  
  2041. FABS(max_y) * 1.01);
  2042.     fprintf(outfile, "      PLANE <0.0 -1.0  0.0> %1.04f END_PLANE\n",  
  2043. FABS(min_y) * 1.01);
  2044.     fprintf(outfile, "      PLANE <0.0  0.0  1.0> %1.04f END_PLANE\n",  
  2045. FABS(max_z) * 1.01);
  2046.     fprintf(outfile, "      PLANE <0.0  0.0 -1.0> %1.04f END_PLANE\n",  
  2047. FABS(min_z) * 1.01);
  2048.     fprintf(outfile, "    END_INTERSECTION\n  END_BOUND\n   \nEND_COMPOSITE\n");
  2049.     fclose(infile);
  2050.     fflush(outfile);
  2051.     fclose(outfile);
  2052.     printf("Finished.\n\nTotal objects written to output file: %ld\n\n",  
  2053. primitives);
  2054.     printf("Total degenerate triangles removed from scene: %ld\n\n",  
  2055. degenerates);
  2056.     printf ("X bounding values range from %f to %f\n", min_x, max_x);
  2057.     printf ("Y bounding values range from %f to %f\n", min_y, max_y);
  2058.     printf ("Z bounding values range from %f to %f\n", min_z, max_z);
  2059.     exit(0);
  2060. }
  2061.  
  2062.  
  2063. int getline()        /* read a group code and the next line from infile */
  2064. {
  2065.     fgets(linbuf, BUFSIZE, infile);    /* get a line from .DXF */
  2066.     if (feof(infile))
  2067.         return(1);
  2068.     sscanf(linbuf, "%3d", &groupcode);  /* scan out group code */
  2069.     fgets(linbuf, BUFSIZE, infile);    /* get a line from .DXF */
  2070.     if (feof(infile))
  2071.         return(1);
  2072.     return(0);
  2073. }
  2074.  
  2075. void writeobj()    /* dump out current object we should have all info on */
  2076. {
  2077.     if (strstr(curobj, "LINE"))        /* a VERY skinny triangle! */
  2078.     {
  2079.         if (xcoords[0] == xcoords[1] && ycoords[0] == ycoords[1] &&  
  2080. zcoords[0] == zcoords[1])
  2081.         {
  2082.             degenerates++;
  2083.             return;
  2084.         }
  2085.  
  2086.         fprintf(outfile, "OBJECT\n");
  2087.         fprintf(outfile, "  TRIANGLE <%1.06f %1.06f %1.06f> <%1.06f %1.06f  
  2088. %1.06f> <%1.06f %1.06f %1.06f> END_TRIANGLE\n", xcoords[0], ycoords[0], zcoords[0],  
  2089. xcoords[1], ycoords[1], zcoords[1], xcoords[1]+0.01, ycoords[1], zcoords[1]);
  2090.         finishobj(curcolor);
  2091.  
  2092.         return;
  2093.     }
  2094.     else if (strstr(curobj, "POINT"))    /* an itty, bitty sphere! */
  2095.     {
  2096.         fprintf(outfile, "OBJECT\n");
  2097.         fprintf(outfile, "  SPHERE <%1.06f %1.06f %1.06f> 0.1 END_SPHERE\n",  
  2098. xcoords[0], ycoords[0], zcoords[0]);
  2099.         finishobj(curcolor);
  2100.         return;
  2101.     }
  2102.     else if (strstr(curobj, "CIRCLE"))    /* a VERY short cylinder! */
  2103.     {
  2104.         fprintf(outfile, "OBJECT\n");
  2105.         fprintf(outfile, "  INTERSECTION\n");
  2106.         fprintf(outfile, "    QUADRIC Cylinder_Z SCALE <%1.06f %1.06f %1.06f>  
  2107. END_QUADRIC\n", floats[0], floats[0], floats[0]);
  2108.         fprintf(outfile, "    PLANE <0.0 0.0 1.0>  0.1 END_PLANE\n");
  2109.         fprintf(outfile, "    PLANE <0.0 0.0 -1.0> 0.1 END_PLANE\n");
  2110.         fprintf(outfile, "  END_INTERSECTION\n");
  2111.         fprintf(outfile, "  TRANSLATE <%1.06f %1.06f %1.06f>\n", xcoords[0],  
  2112. ycoords[0], zcoords[0]);
  2113.         finishobj(curcolor);
  2114.         return;
  2115.     }
  2116.     else if (strstr(curobj, "ARC"))        /* not implemented for now */
  2117.     {
  2118.         return;
  2119.     }
  2120.     else if (strstr(curobj, "TRACE"))    /* 2 back-to-back triangles */
  2121.     {
  2122.         if (checkdegen(0, 1, 2))
  2123.         {
  2124.             degenerates++;
  2125.             return;
  2126.         }
  2127.  
  2128.         fprintf(outfile, "OBJECT\n");
  2129.         fprintf(outfile, "  TRIANGLE <%1.06f %1.06f %1.06f> <%1.06f %1.06f  
  2130. %1.06f> <%1.06f %1.06f %1.06f> END_TRIANGLE\n", xcoords[0], ycoords[0], zcoords[0],  
  2131. xcoords[1], ycoords[1], zcoords[1], xcoords[2], ycoords[2], zcoords[2]);
  2132.         finishobj(curcolor);
  2133.  
  2134.         if (checkdegen(0, 3, 2))
  2135.         {
  2136.             degenerates++;
  2137.             return;
  2138.         }
  2139.  
  2140.         fprintf(outfile, "OBJECT\n");
  2141.         fprintf(outfile, "  TRIANGLE <%1.06f %1.06f %1.06f> <%1.06f %1.06f  
  2142. %1.06f> <%1.06f %1.06f %1.06f> END_TRIANGLE\n", xcoords[0], ycoords[0], zcoords[0],  
  2143. xcoords[3], ycoords[3], zcoords[3], xcoords[2], ycoords[2], zcoords[2]);
  2144.         finishobj(curcolor);
  2145.  
  2146.         return;
  2147.     }
  2148.     else if (strstr(curobj, "SOLID"))    /* 1 or 2 triangles */
  2149.     {
  2150.         if (checkdegen(0, 1, 2))
  2151.         {
  2152.             degenerates++;
  2153.             return;
  2154.         }
  2155.  
  2156.         fprintf(outfile, "OBJECT\n");
  2157.         fprintf(outfile, "  TRIANGLE <%1.06f %1.06f %1.06f> <%1.06f %1.06f  
  2158. %1.06f> <%1.06f %1.06f %1.06f> END_TRIANGLE\n", xcoords[0], ycoords[0], zcoords[0],  
  2159. xcoords[1], ycoords[1], zcoords[1], xcoords[2], ycoords[2], zcoords[2]);
  2160.         finishobj(curcolor);
  2161.  
  2162.         if (xcoords[2] == xcoords[3] && ycoords[2] == ycoords[3] &&  
  2163. zcoords[2] == zcoords[3])
  2164.             return;    /* one triangle was enough... */
  2165.  
  2166.         if (checkdegen(0, 3, 2))
  2167.         {
  2168.             degenerates++;
  2169.             return;
  2170.         }
  2171.  
  2172.         fprintf(outfile, "OBJECT\n");
  2173.         fprintf(outfile, "  TRIANGLE <%1.06f %1.06f %1.06f> <%1.06f %1.06f  
  2174. %1.06f> <%1.06f %1.06f %1.06f> END_TRIANGLE\n", xcoords[0], ycoords[0], zcoords[0],  
  2175. xcoords[3], ycoords[3], zcoords[3], xcoords[2], ycoords[2], zcoords[2]);
  2176.         finishobj(curcolor);
  2177.         return;
  2178.     }
  2179.     else if (strstr(curobj, "TEXT"))    /* not implemented for now */
  2180.     {
  2181.         return;
  2182.     }
  2183.     else if (strstr(curobj, "SHAPE"))    /* these look very hard */
  2184.     {
  2185.         return;
  2186.     }
  2187.     else if (strstr(curobj, "BLOCK"))    /* these look very hard */
  2188.     {
  2189.         return;
  2190.     }
  2191.     else if (strstr(curobj, "ENDBLK"))    /* these look very hard */
  2192.     {
  2193.         return;
  2194.     }
  2195.     else if (strstr(curobj, "INSERT"))    /* these look very hard */
  2196.     {
  2197.         return;
  2198.     }
  2199.     else if (strstr(curobj, "ATTDEF"))    /* not implemented for now */
  2200.     {
  2201.         return;
  2202.     }
  2203.     else if (strstr(curobj, "ATTRIB"))    /* not implemented for now */
  2204.     {
  2205.         return;
  2206.     }
  2207.     else if (strstr(curobj, "POLYLINE"))    /* these look fairly hard */
  2208.     {
  2209.         return;
  2210.     }
  2211.     else if (strstr(curobj, "VERTEX"))    /* these look fairly hard */
  2212.     {
  2213.         return;
  2214.     }
  2215.     else if (strstr(curobj, "SEQEND"))    /* these look fairly hard */
  2216.     {
  2217.         return;
  2218.     }
  2219.     else if (strstr(curobj, "3DLINE"))    /* a VERY skinny triangle! */
  2220.     {
  2221.         if (xcoords[0] == xcoords[1] && ycoords[0] == ycoords[1] &&  
  2222. zcoords[0] == zcoords[1])
  2223.         {
  2224.             degenerates++;
  2225.             return;
  2226.         }
  2227.  
  2228.         fprintf(outfile, "OBJECT\n");
  2229.         fprintf(outfile, "  TRIANGLE <%1.06f %1.06f %1.06f> <%1.06f %1.06f  
  2230. %1.06f> <%1.06f %1.06f %1.06f> END_TRIANGLE\n", xcoords[0], ycoords[0], zcoords[0],  
  2231. xcoords[1], ycoords[1], zcoords[1], xcoords[1]+0.1, ycoords[1], zcoords[1]);
  2232.         finishobj(curcolor);
  2233.  
  2234.         return;
  2235.     }
  2236.     else if (strstr(curobj, "3DFACE"))    /* 1 or 2 triangles */
  2237.     {
  2238.         if (checkdegen(0, 1, 2))
  2239.         {
  2240.             degenerates++;
  2241.             return;
  2242.         }
  2243.  
  2244.         fprintf(outfile, "OBJECT\n");
  2245.         fprintf(outfile, "  TRIANGLE <%1.06f %1.06f %1.06f> <%1.06f %1.06f  
  2246. %1.06f> <%1.06f %1.06f %1.06f> END_TRIANGLE\n", xcoords[0], ycoords[0], zcoords[0],  
  2247. xcoords[1], ycoords[1], zcoords[1], xcoords[2], ycoords[2], zcoords[2]);
  2248.         finishobj(curcolor);
  2249.  
  2250.         if (xcoords[2] == xcoords[3] && ycoords[2] == ycoords[3] &&  
  2251. zcoords[2] == zcoords[3])
  2252.             return;    /* one triangle was enough... */
  2253.  
  2254.         if (checkdegen(0, 3, 2))
  2255.         {
  2256.             degenerates++;
  2257.             return;
  2258.         }
  2259.  
  2260.         fprintf(outfile, "OBJECT\n");
  2261.         fprintf(outfile, "  TRIANGLE <%1.06f %1.06f %1.06f> <%1.06f %1.06f  
  2262. %1.06f> <%1.06f %1.06f %1.06f> END_TRIANGLE\n", xcoords[0], ycoords[0], zcoords[0],  
  2263. xcoords[3], ycoords[3], zcoords[3], xcoords[2], ycoords[2], zcoords[2]);
  2264.         finishobj(curcolor);
  2265.         return;
  2266.     }
  2267.     else if (strstr(curobj, "DIMENSION"))    /* not implemented for now */
  2268.     {
  2269.         return;
  2270.     }
  2271.     return;    /* no current object defined... */
  2272. }
  2273.  
  2274. void finishobj(color)    /* conclude a DKB-style object definition */
  2275. int color;
  2276. {
  2277.     float red, green, blue;
  2278.  
  2279.     lookupcolor(color, &red, &green, &blue);
  2280.     fprintf(outfile, "\n  COLOR RED %1.06f GREEN %1.06f BLUE %1.06f\n", red,  
  2281. green, blue);
  2282.     fprintf(outfile, "  TEXTURE Dull END_TEXTURE\n");  /* default surf. */
  2283.     fprintf(outfile, "END_OBJECT\n\n");
  2284.     printf(".");        /* activity echo (happy dots) */
  2285.     primitives++;        /* count another output file primitive */
  2286. }
  2287.  
  2288. void lookupcolor(color, red, green, blue) /* basic AutoCAD 9-color pallette */
  2289. int color;
  2290. float *red, *green, *blue;
  2291. {
  2292.     switch (color)
  2293.     {
  2294.         case 0:    /* black */
  2295.             *red = *green = *blue = 0.0;
  2296.             break;
  2297.         case 1: /* red */
  2298.             *red = 1.0;
  2299.             *blue = *green = 0.0;
  2300.             break;
  2301.         case 2: /* yellow */
  2302.             *red = *green = 1.0;
  2303.             *blue = 0.0;
  2304.             break;
  2305.         case 3:    /* green */
  2306.             *green = 1.0;
  2307.             *red = *blue = 0.0;
  2308.             break;
  2309.         case 4: /* cyan */
  2310.             *blue = *green = 1.0;
  2311.             *red = 0.0;
  2312.             break;
  2313.         case 5: /* blue */
  2314.             *blue = 1.0;
  2315.             *red = *green = 0.0;
  2316.             break;
  2317.         case 6: /* magenta */
  2318.             *blue = *red = 1.0;
  2319.             *green = 0.0;
  2320.             break;
  2321.         case 8:    /* dk. grey */
  2322.             *red = *green = *blue = 0.5;
  2323.             break;
  2324.         case 9: /* lt. grey */
  2325.             *red = *green = *blue = 0.75;
  2326.             break;
  2327.         case 7: /* white */
  2328.         default: /* make anything else white (?) */
  2329.             *red = *green = *blue = 1.0;
  2330.     }
  2331.     return;
  2332. }
  2333.  
  2334. int checkdegen(a, b, c)        /* check for degenerate triangle structure */
  2335. int a, b, c;
  2336. {
  2337.     if (
  2338.     (xcoords[a] == xcoords[b] &&
  2339.      ycoords[a] == ycoords[b] &&
  2340.      zcoords[a] == zcoords[b]) || 
  2341.  
  2342.     (xcoords[b] == xcoords[c] &&
  2343.      ycoords[b] == ycoords[c] &&
  2344.      zcoords[b] == zcoords[c]) || 
  2345.  
  2346.     (xcoords[a] == xcoords[c] &&
  2347.      ycoords[a] == ycoords[c] &&
  2348.      zcoords[a] == zcoords[c]))
  2349.         return(1);
  2350.     return(0);
  2351. }
  2352.  
  2353.  
  2354.