[PythonCAD] dxf and dwg text escapes and autocad

Eric Wilhelm ewilhelm at sbcglobal.net
Thu Sep 25 23:20:08 EDT 2003


working on calculating text lengths (for placement, dimensions and other fun 
stuff.)

Having not built my own gui (and being stuck in a production environment of 
windows machines and autocad draftsmen), I've got to make it compatible with 
acad's methods of displaying the text.

The % character is quite an interesting escape beast.  If it stands alone, it 
is taken as literal, but two in a row create an escape (which can then be 
followed by a "%" to create a "%" ?!)

>From the looks of it:

%% -> "" (null)
%%% -> "%"
%%37 -> "%"
%%037 -> "%"
%%a -> "a"
%%3 -> "\003" (ascii 3)

Who cooked this up in what dark corner of dos?

An even worse bit is that autocad will save the file as containing the string 
%%037 (or whatever) rather than saving the actual ascii (unlike shell or perl 
programming where entering an escaped character causes the result to be 
saved, the result in autocad only happens onscreen (and on paper.))

My current take is to convert all read files to real ascii and all saved files 
to acad's silliness.  It looks like the incoming could be handled via 
s/%%(\d+)/pack("C", $1)/e, but this will of course skip the other "valid" 
representations (giving a bad string to the program and output, as well as 
throwing-off the length calculations.)  I can see writing a more careful and 
robust algorithm, but I'm afraid it will get caught in a tight loop and take 
up too much time checking every possibility.

That is just on input.  Now apparently output has to be handled 
character-by-character.

I'm now wrestling with how to design the length calculation algorithm and 
whether to accommodate autocad's escape funkiness or just write it off as 
primitive and refusing to work so hard to deal with it.

Any suggestions or experiences would be greatly appreciated.

Thanks,
Eric
-- 
"Everything goes wrong all at once."
                                        --Quantized Revision of Murphy's Law




More information about the PythonCAD mailing list