Autocad doesn't read my DXF file when adding MTEXT - autocad

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:
AutoCad 2021:

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.
DXF R13+ requires an unique handle for each entity (group code 5)
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.
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

Related

WMF: EMRLINETO records from a particular file are not drawn

Attached WMF file contains four LineTo records (with preceding MoveTo's), but programs that can read/show WMF files (I tried Paint, AutoCAD, Metafile Explorer) don't draw them. Three records use NULL pen, ok. But the 4th one uses a non-NUll pen, so at least it should be drawn.
The problem is that I try to parse the file myself for converting to another format and don't see a reason why the line should not be drawn.
More details: coordinates are within header's bounds rectangle, no clipping is used.
The file: https://drive.google.com/file/d/1UIjslJK_6BGlrZ1tv6tBa5i9qvhuFSCc/view?usp=sharing

DXF file - how can "AcDbText" entity with a label text be linked to a geometry entity (AcDbPolyline)?

I suppose there may not be a precise answer to this question, but perhaps I can at least understand working with DXF files better...
I need to process DXF files (floor plans) and link the label, which is usually a room name, to the entity representing the specific room.
I have checked the DXF file and there seems to be no link between the two entities. The TEXT entity has a unique handle (code 5) and it has a soft pointer to another object (I think to the general block definition - code 330) but that is not it. So my questions would be:
do I assume correctly that the only way in this case is to compare the coordinates of the label to coordinates of the "nearest" geometry object? This is doable but what if there are a few overlapping objects - I could see some potential risks there.
Is there a way to include a "precise" link from a text entity to a geometry entity in AutoCAD or similar tools? Perhaps with the use of some attributes? My knowledge of DXF is minimal at this point so if anyone could point me to some documentation or example .dxf files where such "precise link" thing is included, it would be great.
Many thanks!
Is there a way to include a "precise" link from a text entity to a geometry entity in AutoCAD or similar tools? Perhaps with the use of some attributes? My knowledge of DXF is minimal at this point so if anyone could point me to some documentation or example .dxf files where such "precise link" thing is included, it would be great.
There may well be other ways to do what you want. Eg:
Grouping Objects
Attributed Blocks
Also, AutoCAD has a mechanism called Extended Entity Data which is included in any DXF data file (see the link provided).
AutoCAD provides some tools for working with XDATA and you can also use third-party extensions like CADPower and GeoTools that have an arsenal of XDATA tools. And ofcourse, you can write you own plugins to do what you what.
In summary, you could attach the handle of the TEXT as XDATA to the POLYLINE representing the room. Once you have attached the TEXT as XDATA it will be available in the DXF file and you will be able to parse it and locate the handle of the TEXT element.
It isn't too hard to write a VBA macro to run in AutoCAD that asks you to select the two elements and it then add the text entity handle as the XDATA. Then you are good to go.

Using AutoLISP to select multple copies of an object one by one

I am trying out AutoLISP for the first time.
In my AutoCAD drawing I have around 300 copies of an object spread at different places.
I want to mirror each object around a fixed axis in middle of the object.
The first roadblock that I am getting is selecting each copy of the object one by one for doing the mirroring operation.
Can anyone help me with that? Is it possible?
You can obtain an selection using the AutoLISP ssget function with an appropriate mode string and filter list argument permitting selection of objects whose properties meet your selection criteria.
If your selection is to be automated with no user input (for example, using the X mode string to query the drawing database), you will need a property by which to distinguish the target objects from other objects in the drawing - this may depend on the type of object that you are looking to select.
For example, you can filter for all objects of the same type using DXF group 0; within the same layout using DXF group 410; residing on the same layer using DXF group 8; or by other properties, such as colour, linetype, or lineweight.
Filters based on the object geometry will be dependent on the type of object that you are looking to target, for example, a selection of circles of the same radius could be acquired by filtering on DXF group 40; or standard (non-dynamic) blocks of the same name using DXF group 2.
Upon obtaining your selection, you'll then need to iterate over the selection such that the mirror operation can be performed on each object individually (since the mirror axis will be different for every object in the selection). To accomplish this, you can choose one of the methods that I describe in my tutorial on Selection Set Processing.

MS Visio 2010: Saving as .svg sets values to 0

I want to save my Visio shapes as an .svg file to incorporate into a XML document. However, when i save it ALL the values in my shape are set to 0. I've quadruple checked the shape data and all the values are there and the formulas are returning the correct values. The strange thing is, saving as a .svg works in Visio 2007 and all values are correct, but in Visio 2010 all the values are 0. Why is this? Unfortunately this is my first post, so I can't add screenshots as i don't have 10 rep.
The shape is 4 individual rows grouped together. The data is stored in the "Main" shape, i.e all rows grouped together. The cell in the individual shape then references its value from the main shape.
Example of 1 of the 4 main shape row forumlas:
ShapeData Property - Value = Sheet.1!Prop.Row_2 (references main shape rows, stores value)
Text Field Property - Value = Prop.Row_1 (references its single row, containing value of main shape)
The real kick here is I fixed this problem 4 months ago, but my colleagues had more shapes with the same issue. I cannot remember how i fixed it, and the shape that I fixed is identical in terms of structure and data handling.
Something strange that I also noticed is that when i type ".Value" after the Value field text in either the Text Fields or Shape Data properties, the ".Value" gets automatically omitted after I press enter, but then the field produces the right .svg output. However, this does not work when I make that change in the master shape. So effectively, I'd have to go into every single value field and manually type ".Value" and press enter for it to work. I've also tried turning off all shape protection, no joy.
I'm currently in the process of writing a macro to "refresh" all the value fields by adding ".Value" after them to mimic me manually typing that in.
Any help or feedback would be greatly appreciated!
I believe this is upgrade issue (2007->2010). Have seen this a few times. To fix try:
Open the diagram in Visio 2003 (or 2007), but not in Visio 2010
Save it as .VDX (Visio XML Drawing) file
Close it
Open the VDX file again in the same Visio
Save it back as normal VSD file. This should fix the broken VSD file.
Delete the VDX file, it is not needed
If this doesn't work then try sharing the source file (dropbox or whatever).
The problem was that the rows Text Fields were Data Object types. When I removed the Text shape protection and inserted a Shape Data field, the correct values were shown on the .svg output file.

iTextSharp stamper wraps text

I'm using iTextSharp to fill in some stamper AcroFields.
stamper.AcroFields.SetField("Title", "Lipsum");
I created the pdf in illustrator and the form fields with Adobe Acrobat X Pro. The problem is that although the text fields are the width of the page, in the saved pdf the text wraps at about 1 third of the width.
Another question would be if it's possible the have the textfield autoSize in height, or a way to handle the overflow of the text.
1) I'd like to see that PDF. I suspect the fields aren't as wide as you think they are.
2) You can set a field's font size to zero to enable "auto sizing", which works both within Reader and iText. However, it sizes to the actual field size, not what you think it might be.
I'm guessing you drew a spiffy form field background in Illustrator, then put a field over it in Acrobat Pro, but didn't size the field width to match the spiffy illustrator background. Could be wrong, but that's my hunch.
That's the flattened PDF. Can I see the original with the form field still intact? Sorry I wasn't more specific. None the less, I can learn a little from reading this PDF:
Looking at the bounding boxes for the flattened field XObject and it's internal clipping rectangle, it looks like it should be using most of the page:
The page is ~600 points wide by ~850 tall.
The flattened field XObject is ~560 points wide by ~100 tall.
I wonder if there's some non-standard carriage return characters in your text that iText picks up on by Acrobat does not...
Anyway, I'd like to see the unflattened PDF. Filled in is good, but not flattened.
Okay, looked at the template. I don't see anything that would cause the line breaking you're seeing... which makes me think my second guess was right: new line characters.
Looking at the text layout code might give me a hint. Each of your lines of text goes like this (for example):
1 0 0 1 2 88.24 Tm 0 g (Die Semmerrolle der l{e4}nge nach zu einer grossen Roulade)Tj
n n n n n n Tm: text matrix
g: gray (0 g: black)
(...)Tj: show text
That's consistent with the code path when you set a text field value in the trunk of iText (and the most recent release[s]). That code (ColumnText) is quite good at breaking text properly, and used all over the place. The bounding box is correct (as shown in a couple places of the flattened PDF).
Check your input.

Resources