Understanding the Diesel Marco Language AutoCad Help

If you browse through the Acad .mnu file, you’ll see many menu options that contain odd-looking text beginning with J dollar sign (S). In some instances the dollar sign is used to tell AutoCAD to open a popup menu. But in many cases it is used as part of the Diesel macro language. Diesel is one of many macro languages AutoCAD supports and it can be used to perform some simple operations. Like AutoLISP it makes use of parentheses to enclose program code.

You can actually use Diesel at tilt’ AutoCAD command line using a command called Modemacro. The Modemacro command sends information  to the status  line. Diesel can be used with Modemacro to perform some simple tasks. Try the following exercise to try Diesel for yourself.

1. Type Mode macro.   the command prompt.
2.. At the Enter new value for MODE MACRO or  for none: prompt enter $(/,25,2).J. You’ll see the answer to the equation in the far-left side of the status line.

3. To clear the status line enter Mode macro.

The equation you entered in step 2 is referred to as an expression. The structure of Diesel expressions is similar to that of AutoLISP. The dollar sign tells AutoCAD that the information that follows is a Diesel expression.

A Diesel expression must include an operator of some sort, followed by the items to be operated on. An operator is an instruction to take some specific action such as adding two numbers together or dividing one number by another. Examples of .mathematical operators include the plus sign (+) for addition and forward slash (I)
for division.

The operator is often referred to as a function and the items to be operated on as the arguments to the function or simply the arguments. So in the expression (1 25 2) the / is the function and the 25 and 2 are the arguments. All Diesel expressions no matter what size, follow this structure and are enclosed by parentheses.

Parentheses are important elements of an expression. All parentheses must be . balanced; for each left parenthesis, there must bell right parenthesis.

You can do other things with Diesel besides performing calculations. In Chapter 19 you used Diesel to place text in the drawing using the Remote Text tool. There the Getvar function was used to obtain the drawing prefix and name, which Remote Text converted into text in the drawing. ‘fry the following to see how Diesel-uses Getvar.

1. Type Modemacro.J again.
2. Type $(getvar,dwgprefix).J. The location of the current drawing appears in the status bar.
3. Press .J to reissue the Mode macro command then type $(getvar,dwgname).J Now the name of the drawing appears in the status bar.

In this example the Getvar function extracts the drawing prefix and name and displays it in the status line. Getvar can be used to extract any system variable you want. If you’ve been working through the tutorials in this book you’ve seen that virtually’ 11AutoCAD settings are also controlled through system variables. (Appendix D contains a list all the system variables.) This can be a great tool when you are creating custom menus because with Getvar, you can “poll” AutoCAD to determine its state. For example you can find out what command’is currently being used. Try the following exercise to see how this works.

1. Click the Line tool in the Drawing toolbar.
2.Type Modemacro. The apostrophe at the beginning ofModemacro lets you use the command while in another command.
3. Type $(getvar,cmdnames).J. The word 1; ne appears in the status bar indicating that the current fommand is the Line command.

Diesel can be useful in a menu when you want your menu option to perform a specific task depending on which command is currently active

Using Diesel in a Menu

So far you’ve been experimenting with Diesel through the Mode macro command. To use Diesel in a menu requires a slightly different format. You still use the same Diesel format of a dollar sign followed by the expression, but you don’t use the Mode macro command to access Diesel. Instead you use SM You can think of SMas an abbreviation for Modemacro.

Using Diesel as a Menu Option Label

In the previous example you saw how Diesel can be used in a menu to read the status of a command then return a numeric value to alter that status. You can also use Diesel as part of the menu option label. The following expression shows the same menu listing you’Ve already seen, with a twist. It includes Diesel code as the menu option label, as follows:

NOTE

When Diesel is used as the menu name: you don’t need the SM- code.

Normally you see the menu name within the square brackets at the beginning of this menu listing but here you see some Diesel instructions. These instructions tell AutoCAD to display the message B1 i pmode = lor B1 ipmode = 0 in the menu,
depending on the current Blipmode setting.

Here’s how it works. fou see the ‘familiar $(getvar, b1ipmode) expression, this time embedded within a different expression. You know that $(getvar ,b 1; pmode)

the Index tab. Enter Diesel in the input box at the top and you’ll see a listing of topics that deal with Diesel.

For fun, try adding this Blipmode menu listing to your Mymenu .mnu file under the [Conti nue L; ne] option, then reload the menu file and check the results.[S(eval,”Blipmode ” S(if,S(getvar,blipmode),’Off’,’On”))]’BLIPMODE
SM-S(-,l,S(getvar,blipmode)) Make sure the last line in your menu file is followed by a .J.

If you feel you’ve learned enough to do some work with Diesel, Table 20.2 shows some of the commonly used Diesel functions. Check the AutoCAD Help Topics dialog box for a more detailed list.

Posted on November 9, 2015 in Integrating AutoCAD into Your Projects and Organization

Share the Story

Back to Top
Share This