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.
^C^C_Setvar;fielddisplay;0;_Undo;;;control;none;
_Select;\_Change;previous;;0,0;0;
_Rotate;previous;;0,0;$M=$(-,0,$(*,$(edtime,$(getvar,date),SS),6));
_Script;AutoClock.scr
Let us have a look at the macro in detail.
- _Setvar;fielddisplay;0;
Sets field display for the digital elements. - _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. - _Select;\_Change;previous;;0,0;0;
Resets the seconds needle to the default position (towards 12). - _Rotate;previous;;0,0;$M=$(-,0,$(*,$(edtime,$(getvar,date),SS),6));
Moves the seconds needle to the current seconds position. - _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).
_Rotate
previous
0,0
-6
delay 1000
Regen
rscript
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.