DIESEL Expressions in Macros
 
 
 

You can use DIESEL string expressions in customization (CUI) files as an additional method of creating macros.

These expressions can return string values (text strings) in response to standard AutoCAD commands, AutoLISP and ObjectARX® routines, and other macros. They can also return string values to the menu itself, thereby altering the appearance or content of a menu label.

This string provides a way to toggle between paper space and model space if TILEMODE is set to 0. This expression is evaluated transparently. If the special character ^P (which toggles MENUECHO on and off) is omitted, the expression displays only the issued command.

A DIESEL expression that you use in a menu item must follow the $section=submenu format where the section name is M and the submenu is the DIESEL expression you want. Frequently, you can implement a macro more easily with AutoLISP.

The following examples show two menu items that produce the same result; one uses DIESEL, and the other uses AutoLISP.

This menu item uses the DIESEL expression:

^C^C^P$M=$(if,$(=,$(getvar,cvport),1),mspace,pspace)

This menu item uses the AutoLISP expression:

^C^C^P(if (= (getvar "cvport") 1)(command "mspace")+
(command "pspace"))(princ) ^P

Both menu items provide a way to switch between paper space and model space (if TILEMODE is set to 0), but the DIESEL expression is shorter and is evaluated transparently, not requiring the call to the AutoLISP princ function. If the special character ^P (which switches MENUECHO on and off) is omitted in both cases, the DIESEL expression displays only the issued command, whereas the AutoLISP expression displays the entire line of code.

Because the value returned by a DIESEL expression is a text string, it can be used in response to an AutoLISP getxxx function call. This functionality enables menu items to evaluate current drawing conditions and to return a value to an AutoLISP routine.

The next example is based on these assumptions:

If you load and execute the sample AutoLISP routine, AutoCAD inserts the symbol at the size and location you have specified. When plotted, the symbols are the specified size (if the drawing is plotted at the same scale as that specified by DIMSCALE).

The following is a sample AutoLISP routine.

(defun C:SYMIN ( )
  (setq sym 
    (getstring 
      "\nEnter symbol name: ") ; Prompts for a symbol name
  ) 
  (menucmd "s=symsize")        ; Switches the screen menu 
                               ;  to the symsize submenu 
  (setq 
    siz (getreal 
      "\nSelect symbol size: ") ; Prompts for a symbol size
    p1 (getpoint 
      "\nInsertion point: ")   ; Prompts for insertion point
  ) 
  (command "insert"            ; Issues the INSERT command
    sym                        ;  using the desired symbol
    p1 siz siz 0)              ;  insertion point, and size
  (menucmd "s=")               ; Switches to the previous
                               ;  screen menu
  (princ)                      ; Exits quietly 
)
NoteAn AutoLISP routine that you use regularly should include error checking to verify the validity of user input.

The DIESEL expressions in the following example multiply the current value of DIMSCALE by the specified value, and return an appropriate scale factor.

This cannot be done with similar AutoLISP code; a value returned by an AutoLISP expression cannot typically be used as a response to a getxxx function call (such as, the getreal function in the preceding sample).

$M=$(*,$(getvar,dimscale),0.375)
$M=$(*,$(getvar,dimscale),0.5)
$M=$(*,$(getvar,dimscale),0.625)

DIESEL expressions can also return string values to pull-down menu item labels, so that you can make menus unavailable or otherwise alter the way they are displayed. To use a DIESEL expression in a pull-down menu label, make sure that the first character is the $ character.

In the next example, the current layer is set to BASE and the following DIESEL expression is used as the label.

$(eval,"Current layer: " $(getvar,clayer))

The result is that the appropriate pull-down menu is displayed and updated whenever the current layer changes.

Current Layer: BASE

You can also use this method to interactively change the text displayed in a pull-down menu. You use an AutoLISP routine that sets the USERS1-5 system variables to the selected text, which can be retrieved by a DIESEL macro in a menu label.

NoteThe width of pull-down and shortcut menus is determined when the customization file is being loaded. Menu labels generated or changed by DIESEL expressions after a menu is loaded are truncated to fit within the existing menu width.

If you anticipate that a DIESEL-generated menu label will be too wide, you can use the following example to ensure that the menu width will accommodate your labels. This example displays the first 10 characters of the current value of the USERS3 ( USERS1-5) system variable.

$(eval,"Current value: " $(getvar,users3))+
 $(if, $(eq,$(getvar,users3),""), 10 spaces )^C^Cusers3 

You cannot use trailing spaces in a menu label to increase the menu width, because trailing spaces are ignored while the menu is being loaded. Any spaces you use to increase the width of a menu label must be within a DIESEL expression.

The next example uses the same DIESEL expression as the label and a portion of the menu item. It provides a practical way to enter the current day and date into a drawing.

$(edtime,$(getvar,date),DDD", "D MON YYYY)^C^Ctext +
\\\ $M=$(edtime,$(getvar,date),DDD", "D MON YYYY);

Also, you can use a DIESEL macro to mark pull-down menu labels or make them unavailable. The following pull-down menu label displays an unavailable ERASE while a command is active. The text is displayed normally when a command is not active.

$(if,$(getvar,cmdactive),~)ERASE

You can use a similar approach to place a mark beside a pull-down menu item or to interactively change the character used for the mark.

Commands
System Variables
Utilities
Command Modifiers