Wednesday, August 27, 2008

AutoClock - An AutoCAD Digital cum Analog Clock Using AutoCAD Script and DIESEL

Here is an AutoCAD digital cum (partially) analog clock developed using a combination of AutoCAD Script and DIESEL. It shows current time in digital format updated as in a normal digital clock plus date and month along with a rotating seconds needle. I hope this program will help us to learn how to combine DIESEL and script effectively to acheive powerful results. The macro and script are pretty simple as illustrated below.


Let us have a look at the macro in detail.

  1. _Setvar;fielddisplay;0;
    Sets field display for the digital elements.

  2. _Undo;;;control;none;
    Disables Undo action. If the Undo is on, it will consume a lot of memory in a long run resulting in application instability.

  3. _Select;\_Change;previous;;0,0;0;
    Resets the seconds needle to the default position (towards 12).

  4. _Rotate;previous;;0,0;$M=$(-,0,$(*,$(edtime,$(getvar,date),SS),6));
    Moves the seconds needle to the current seconds position.

  5. _Script;AutoClock.scr
    Runs the script to update the clock at an interal of 1 second.

Arrange the above macro in a button and place the following script inside a text file named 'AutoClock.scr' and keep it somewhere inside the AutoCAD search path (for example, inside AutoCAD support directory).


delay 1000

If you want to try AutoClock, then download the required files and follow the instructions inside the readme file. To activate the clock, run the above macro and select the seconds needle when select objects prompt is displayed. The seconds needle accuracy may vary depending upon the command execution time. You can fine tune the clock accuracy by adjusting the delay. A delay just above 900 in place of 1000 works fine for me.

No comments: