Awk is a good language for processing text and summarising large text files. It has associative arrays, and awk runs quite well on win3.1 to Win 98 and is very portable. You just need a good text editor like PFE and a DOS box. Write your awk script to process your data, include some of my graphics functions and your script will output DXF formated graphics commands, capture these to a text file, and import into a CAD package.
Here is a simple example of some output:
I work in telecommunications and we regularly get 1Mb files of output in text from our protocol testers.
Sometimes we get complex problems, which are lost in the mass of information. We get complex databuilds, which need summarising, using simple 2D graphics. I originally wanted a 'panio roll' plot of call activity on each circuit on a trunk group.
What I wanted was a simple set of graphics functions that I could call from one of my awk scripts. The Awk script would output DXF commands which could be captured to a file. This file can be opened by DeltaCad, and the graphics adjusted, annotated and copied and pasted into a document written in Word97. Ease of use was essential. Speed of change of the awk script to suit the problem at hand makes it for me.
Awk provides the best front end for me. Perl could be used, but BMAWK runs really well on my Win 3.1 based protocol analyer and my Win98 desktop machine.
Word 6 would import HPGL files, but this was lost when we went to Word 97. I could not get Word 97 to import text based graphics files, so I would have to go to a C or Pascal and these would have to output the WMF files. Delphi1.0 does not support these. These are serious programming languages that take a serious time to program.
At a computer fair, I found a copy of DeltaCad 2.3, which imports DXF files. These are rather verbous text files, but DeltaCad exports and imports them well enough for what I wanted. Actually, it is the best program I have found for a very long time. Quick to load and simple to do techinal drawings in.
DeltaCad has two super features. It scales drawings very easily and also has a massive canvas, with a number range -100,000.0000 to +100,000.0000 or 10^9 values, whereas HPGL is 32K or 2^16 values, and Word would not import massive diagrams, simply.
You do not need to spend time getting the drawing to fit an A4 page. Scale it with DeltaCad, and cut and paste the picture into word. It cuts a windows metafile format which pastes into Word, which can then be resized, without the normal problems of bitmaps.
The current build of my desktop PC at work also enables Word97 to import .dxf files. DeltaCad is much, much, much better than Word97's dxf import filter, for large drawings.(For the Word 97 filter, you will need to adjust the $EXTMIN and $EXTMAX in the header of the .DXF file so that your drawing fits into the box specified by $EXTMIN and $EXTMAX. )
The code and demo with a copy of BMAWK and DXF R13 help file is in the following zip file: awk_fns.zip
These functions were written by exporting a dxf file from DeltaCad, and finding out what it had output for the simple objects. I used DeltaCad 2.3 originally, but DeltaCad now supports more fonts and colours. DeltaCad also supports layers in the DXF, but I have not used them.
Here are the functions that I have written so far:
######################################################### # # Awk Functions # Copyright 2002 Doug Rice # # # ---------- dxf_fns.awk # function line( x1, y1, x2, y2, colour ) # function dottedline( x1, y1, x2, y2, colour ) # function point( x1, y1, x2, y2 ) # function text( x1, y1, angle, s1 ) # function text_Centered( x1, y1, angle, s1 ) # function F_insert( x1,y1,name ) - Inserts a Grouped object. # # function F_header() - needed once at start of Awk Script # function F_end () - needed once at start of Awk Script # #############################################################################################################
This is a simple demo of including line and text functions in a simple awk script.
T.TXT is a simple text based data file. You can write more complex awk to analyse your data as you wish.
#################################################### # # T.awk - A simple demo # # usage: bmawk -f t.awk -f dxf_fns.awk t.txt > t.dxf # # doug rice, (c) 2011 # #################################################### BEGIN { FS = "," lastX = 0 lastY = 0 # set size of graph xl = -6 xr = -1 yt = 6 yb = 0 # Start the DXF file F_header() # draw grid for ( x = 0 ; x < ( xr - xl ) ; x ++ ) { line( xl+x,yb ,xl+x,yt ,9) } for ( y = 0 ; y < ( yt - yb ) ; y ++ ) { line( xl, yb+y,xr ,yb+y,9) } # The message sets the state for the next line for ( x = 0 ; x < 10 ; x ++ ) { line( 0,x*0.5,2,x*0.5,x) line( 0,x*0.5+0.2,2,x*0.5+0.2,x) text( 2.5, x*0.5, 0, "** "+x ) } } /data/ { line( lastX-6,lastY,(NR / 2)-6,$2*1,1) text( (NR / 2)-6,$2*1, 0, "** " (NR / 2)-6 "," $2*1) lastX = NR / 2 lastY = $2*1 } END { # draw box # top and bottom line(xl,yb,xr,yb,0) line(xl,yt,xr,yt,0) # left and right line(xl,yb,xl,yt,0) line(xr,yb,xr,yt,0) # line( 0,0,100,0,0) # black # line( 0,1,100,1,1) # red # line( 0,2,100,2,2) # yellow # line( 0,3,100,3,3) # green # line( 0,4,100,4,4) # cyan # line( 0,5,100,5,5) # blue # line( 0,6,100,6,6) # magenta # line( 0,7,100,7,7) # Black # line( 0,8,100,8,8) # black # line( 0,9,100,9,9) # black # And finally tidy up the DXF file F_end() } #############################################################################################################
Run the demo using for following command in a DOS box:
bmawk -f t.awk -f dxf_fns.awk t.txt > t.dxf
Open the file into DeltaCad and you get a diagram like the one below, which I cut and pasted into FrontPage Express for this Web page:
DeltaCad 2.3 had a limited number of colours and fonts. I now have brought DeltaCad 5 from http://www.deltacad.com. This is better, as it also allows macros in Cyprus Enable Basic.
You could write some macros to scale and resize text and put title boxes onto drawings.
It is a really good, but simple Technical Drawing CAD program.
The code and demo with a copy of BMAWK is in the following zip file: awk_fns.zip
If you use these functions and find them useful, please email me or sign my guestbook. This is postcard ware.
Doug Rice,
Copyright, 14th March 2002