DIESEL Programming for AutoCAD


Step 1

DIESEL = Direct Interpretively Evaluated String Expression Language

AutoCAD is not weded to a single customization tool, so you have got DIESEL just to customize the status bar. As the name suggests, DIESEL is a language that deals mostly with strings.


Step 2

It is assumed that you are familiar with some AutoCAD version higher of R12.

Also, you understand the importance of the status bar and have prior programming experience with atleast one of the 8 programming paradigms that the open architecture of AutoCAD supports.

DIESEL is number nine. (and ARX is No.10)




.
Step 3

As commonly perceived, DIESEL is not just a tag language like DCL, but it is also not a full blown programming language with loops, iterations and subfunctions like AutoLISP.

Boy ! its different.

DIESEL has two major applications in AutoCAD :

  • It can be used to display a user-defined text string (macro expression) in the status bar by altering the value of the AutoCAD system variable MODEMACRO.
  • You can also define a DIESEL expression in the screen, tablet, pull-down or button menu.

  • Drop it on the Status Bar
    Step 4

    The AutoCAD system variable MODEMACRO can be used to display a new text string in the status line.

    The value returned by a macro expression using DIESEL can also be displayed in the status bar.

    Start AutoCAD and type modemacro at the Command: prompt.


    As shown in figure above, AutoCAD prompts for a new value.
    Type a word and press Enter.
    The word (string) is immediately displayed in the status bar as shown.

    Step 5

    Macro expression using DIESEL

    The return value of a macro expression written using DIESEL can be passsed to the modemacro system variable to be displayed in the status bar.

    The macro expressions are similar to AutoLISP functions, with some differences.

    For example, to add two numbers, the AutoLISP function is written as (+ 2 3) whereas, in DIESEL the same thing is written as $(+,2,5)

    The general syntax for DIESEL expressions is :

    $(FunctionName,Argument1,Argument2,....)

    .
    In AutoLISP, spaces between function and the arguments are required



    In DIESEL, the commas between function and the arguments are required, but no spaces are allowed anywhere in the expression

    Step 6

    Lets try this out immediately.


    Type modemacro at the AutoCAD Command: prompt and press Enter at the keyboard.
    As shown in figure, type $(+,2,3) without any spaces anywhere in the expression and press Enter.

    As shown circled red in figure, the return value of the expression is displayed in the status bar, ahead of the coordinate display.

    Step 7

    To display the current text style in the status bar, use the expression :

    Current Text Style is : $(getvar,textstyle)

    To know the maximum number of characters that can be displayed in the status bar, use the expression :

    $(linelen)



    .
    Step 8

    To display the current date with day, month, year and time, use the expression :

    $(edtime,$(getvar,date),DDDD"," DD MONTH YYYY - HH:MM AM/PM)



    The format and output for the edtime function are summarised below :

    Format : Output

    D : 5
    DD : 05
    DDD : Tue
    H : 2
    HH : 02
    MM : 23
    DDDD : Tuesday
    M : 1
    MO : 11
    MON : Nov
    MONTH : November
    YY : 92
    YYYY : 1992
    SS : 12
    MSEC : 325
    AM/PM : PM
    am/pm : pm
    A/P : P
    a/p : p

    Step 9

    DIESEL expressions can get as long as in the previous step.

    You can integrate AutoLISP and DIESEL.

    A simple AuoLISP routine that builds DIESEL expressions is shown on the right.

    Another AutoLISP routine that lets you enter DIESEL expressions directly at the AutoCAD Command: prompt by avoiding the modemacro system variable is available on the Source Code page of the CadGuruCool site at :

    wwww.geocities.com/CadGuruCool

    
      (defun c:etm()
      (setvar "MODEMACRO"
      (strcat
        "Text Style : $(getvar,textstyle)"
        " Elasped Time : $(fix,$(*,60,$(*,24,
        $(getvar,tdusrtimer))))"
        )
       )
      )
    

    Step 10

    The MACROTRACE system variable is used to debug a DIESEL expression.

    By default, its value is 0 meaning debugging is OFF.

    Type MACROTRACE at the AutoCAD Command: prompt and press Enter, then type 1 and press Enter to make DIESEL debugging ON.

    Next, we will assign a faulty expression to the modemacro system variable.

    Assign this expression :

    $(getvar,dwgname),$(getvar clayer)


    Notice that in the second expression, the comma between getvar and clayer is missing.

    AutoCAD displays an error message in the Command: prompt as shown on the right (above)

      
    AutoCAD Error message Eval:$(GETVAR,DWGNAME) = = = = > UNNAMED Eval:$(GETVAR CLAYER) Err: $(GETVAR CLAYER)??
    Error Message : Meaning $? : Syntax error $?(func,??) : Incorrect argument to function $(func)?? : Unknown Function $(+ +) : Output string too long

    Step 11

    Modemacro in menu customization

    A typical case of the use of DIESEL in screen menu customization is shown on the right.

    You may want to download another severely indepth and illustrated tutorial on menu programming at :

    www.geocities.com/CadGuruCool


      
    ***screen [ShowText]^c^cMODEMACRO;$M=$(getvar,textstyle) [PlineFillet]^c^cmodemacro;$M=$(getvar,plinewid),+ $(getvar,filletrad) [DWGdim]^c^cModeMacro;$M=$(getvar,dwgname),+ $(getvar,dimasz)