cart: empty [ Login ]

TEXT/MTEXT issues

1 
FizixMan
3/23/2007 9:09 PM
Our company purchased the library (working great so far), and recently hit a snag with this. Seems like the library isn't reading in the TEXT entity type. I loop through all the entities and it's not picking up. In the newer DXF versions where they use MTEXT, the DxfMText.Text property is returning all the formatting junk given to the text. i.e. {\fTahoma|b0|i0|c0|p34;TEST} Not sure if this is expected or not. I don't mind having to parse that if I have to. Probably related, but the DxfMText.Style.FontFamily.Name returns 'Arial' instead of the expected 'Tahoma' in this case. I've attached three files. They're renamed to '.txt' so the forum would allow them as attachments. 'mtexttestv18.txt' - uses MText entity, version 18. 'texttestv15.txt' - uses Text entity, version 15. 'texttestv21.txt' - uses Text entity, version 21. They also include a simple drawing of lines to make sure it was actually reading the entities properly. I imagine this is something pretty simple, probably overlooked on my side. Quick sample of the code I'm using to search through:
C# Code:
foreach (DxfEntity e in data.entities) {    Console.WriteLine(e.EntityType); }
Thanks for the help. :)
Wout
3/23/2007 9:45 PM
About your files with TEXT entities, I see they are part of a BLOCK, so you won't find them directly under DxfModel.Entities. They will be indirectly referenced through the DxfInsert, DxfBlock classes (see DxfBlock.Entities). One more point to pay attention to, if they were in paper space, the entities would show up in the appropriate paper space DxfLayout.Entities in stead of the DxfModel.Entities (which represents model space). Your files are probably in model space mostly, so you don't have to worry about the paper space, but it's good to be aware of it. I just noticed the documentation wasn't terribly clear on this, so I improved it and just uploaded a new .msi, feel free to update :)! About the MTEXT: the text field indeed contains formatting stuff, that isn't further split out by CadLib into separate objects. For the rendering CadLib does split the text into objects internally, so it does understand most of the formatting in there, but it's a one way translation just for rendering. Since one MTEXT can have text pieces with multiple fonts, sizes etc, the info DxfMText.Style is unrelated to that, so that's correct: the tahoma font does not necessarily have to be in the text style. There is some more details about all the formatting codes with the DxfMText class documentation. Thanks, Wout
FizixMan
3/24/2007 9:17 PM
Ahh, that makes sense. Thanks a bunch! So if I understand it right, my algorithm for picking up the entities should look more like this:
C# Code:
foreach (DxfEntity e in data.entities) {    if (e.EntityType == 'INSERT')    {       //recurse through e.Block.Entities    }    else    {       //check for other entities not within a block    } }
Thanks for the heads up about the paper space. Hopefully we won't need to worry about that. Thanks again for the speedy and great replies! Again, I'm very impressed with the library.
Wout
3/24/2007 9:56 PM
Apologies for being picky ), but this would be slightly cleaner (initial call with model.Entities as parameter):
C# Code:
public void LookForText(DxfEntityCollection entities) {   foreach (DxfEntity entity in entities) {     DxfInsert insert = entity as DxfInsert;     if (insert != null) {       // Recurse into the block.       LookForText(insert.Block.Entities)     }     DxfText text = entity as DxfText;     if (text != null) {     }   } }
Another note: you'll be likely to process the same block more than once, because multiple inserts may refer to the same block. So you might want to process all blocks, cache the result and then go over all inserts using the cached results. Wout
FizixMan
3/26/2007 4:19 PM
Actually, the snippet you have there is nearly the same thing I already wrote. I just wrote out some pseudo code. Glad to know I'm thinking on the right track!
1