Calaf
Calaf

Reputation: 1173

Autocad doesn't read my DXF file when adding MTEXT

Premise

I wrote a method that allows creating a dxf file with some graphics entities: lines, polygons, texts... All works perfectly, and my dxf can be read from every program I tried.

Problem

Now I want to add a new Entity: a text bounded in a rectangle. Like the other entities, I searched for the right dxf equivalent and I followed this group codes table. This MTEXT is properly showed in every online dxf reader I tried, but not in AutoCad: when I try to open my dxf with the MTEXT, an error occurs and nothing is shown. What could be the problem?

My attempt

Here is the MText part of my dxf. To make it more understandable, I added comments marked with // (which are not present in the file, of course):

0         //Entity
MTEXT
8         //Layer
0
62        //Color
   135
1         //Text
This\Pis a beautiful example.
10        //x
0
20        //y
200
40        //Nominal (initial) text height
16
41        //Reference rectangle width
50
71        //Attachment point: 1 = Top left
1
72        //Drawing direction: 5 = By style
5
50        //Rotation angle in radians
0
90        //Background fill setting: 0 = Background fill off
0

I've also tried to add all nonoptional tags, but the result is the same...

Output

Generic dxf viewer:

enter image description here

AutoCad 2021:

enter image description here

Upvotes: 0

Views: 729

Answers (1)

mozman
mozman

Reputation: 2239

AutoCAD is only nice and accommodating up to DXF version R12, from DXF version R13+ AutoCAD is very picky. MTEXT requires at least DXF R13+ and therefore it is much more work to do to create a DXF file which AutoCAD accepts. The error messages are often not very helpful and much information is missing in the DXF reference.

  1. DXF R13+ requires an unique handle for each entity (group code 5)

  2. DXF R2000+ requires an owner handle (group code 330). DXF R13/14 may not need a owner handle. The owner handle is the handle of the BLOCK RECORD of the layout in which the entity resides. For DXF R13+ the BLOCK RECORD is the central structure to manage blocks and layouts, because the BLOCK RECORD "owns" all the entities, not the BLOCK or LAYOUT.

  3. DXF R13+ separates the data of different subclasses (C++ internals of AutoCAD) by subclass markers. There are two missing subclass markers, first the (100, "AcDbEntiy") which marks the begin of common DXF properties like layer and linetype. The second is the (100, "AcDbMText") maker for the begin of the MTEXT specific attributes.

Your code (before MTEXT) may have worked, because you only used DXF R12 entities and AutoCAD ignored features from later DXF versions.

If you implement DXF R2000+ support you also have to add further required structures: https://ezdxf.mozman.at/docs/dxfinternals/filestructure.html#minimal-dxf-content

Upvotes: 1

Related Questions