TIME TO PLOT (datm.lsp)

Ever had two plots of the same drawing and had to determine which had been plotted later? This month we will look at a program that will stamp the current date and time into a drawing immediately before plotting. DATM.LSP will extract the system time and insert a block with two attributes into your drawing, one attribute displaying the date and the other, the time.

The Listing

After the program description, the program is given its name, DATM, and variables that it uses are localized. A SETQ function sets a number of variables, starting with the setvars "CMDECHO", "OSMODE", "ATTDIA", "BLIPMODE" and "DIMSCALE". The first four are used for saving values for restoration at the end of the program whereas the fifth will be used later as a scaling factor. Variable DATE2 is then set to the value of the CDATE setvar converted to a string and truncated to four decimal places. The CDATE setvar displays the current system time as a real number in the form of YYYYMMDD.HHMMSSmsec (msec is actually only three digits). CDATE therefore is a string containing the system time in the form of "YYYYMMDD.HHMM". We then set variable YEAR2 to the last two digits of the year by extracting a sub-string from the DATE2 variable. This is done by passing the SUBSTR function three arguments: the string in variable DATE2, the integer 3 and the integer 2. This results in a string starting with the third character in DATE2 and continues for two characters. In like manner, the month, day, hour, and minutes are extracted and stored in variables with names that indicate what they contain.

The day, month and year values are then concatenated together with a dash (-) between them as a separator and this is stored in variable DATE3. The hours and minutes are also concatenated but with a colon (:) as a separator. The SETQ function finishes by searching the drawing for a block insertion with the name of DATM. If it exists, variable DTMB2 will be set to a selection set containing the object name of the block insertion. If it doesn't, DTMB2 will be set to nil.

Command echoing, object snaps, the attribute dialogue box and blips are then turned off. The UNDO command is then used to group the actions of the program into a single UNDO item.

Variable DTMB2 is then checked for a value and if it has one (an insertion of the DATM block was found) the IF's then-expression, grouped by a PROGN, will run. This will extract the block insert's name, insert point and scaling values, delete the block insertion and then insert a new instance of the block. The extracted values for insert point and scaling are used for the new insertion. The values in variables DATE3 and TIME2 are used for the two attributes the block needs to have.

In the event that no previous insertion of the DATM block existed in the drawing, the IF function's else-expression will be run instead. This starts with an IF function which checks if the drawing is in paper space. Since paper space drawings are almost always plotted at 1:1, the DATM block is inserted at a scale of 1. A default insertion point of 0,0,0 is used. If the drawing is not in paper space, the IF's else-expression will insert the DATM block at the default 0,0,0 location but at the same scale as the DIMSCALE value (in variable DS2). This usually ensures that the scaling of the block insert matches that of your drawing.

The IF functions are then closed and the UNDO group is ended. Setvars that had been changed by the program are restored and the PRINC function prevents the value of CMDECHO from being printed to the command line as the program exits.

Using DATM.LSP

To create the DATM block, use an existing drawing to help you locate and size it. Draw it up as you would like it to appear and using the ATTDEF command create two attributes, the first one for the date, the second for the time. The one I use has the text "Plotted on", then an attribute to the right of it, then an "@" symbol and then another attribute. Not particularly fancy but it works.

You may even wish to incorporate a box inside your drawing border for the DATM block. Then by using the WBLOCK command, write it out to disk, using 0,0 as the base point, preferably to a directory in one of AutoCAD's search paths. The \SUPPORT\ directory is a good one to use.

Add the line (DEFUN C:DATM()(LOAD "DATM")(C:DATM)) into your ACAD.LSP file. Next edit your menu files to incorporate a DATM; in front of your PLOTs. They should then look like ^C^CDATM;_PLOT. If you are running Release 11 or earlier, you won't have the underscore (_) preceding the PLOT.
 

©1996-2001 ZOTO Technologies