DIESEL
(Direct Interpretively Evaluated String Expression Language)

  Site Map

Index Index
   AutoCAD LT
AutoCAD LT
      Tips & Tricks
Tips & Tricks
      DIESEL
DIESEL
        
Defined
        
Listing of Functions
        
Storing Variables
        
Evaluation Sequence
        
Getting User Input
        
Errors
         Examples
Examples
      System Variables System Variables
      Custom Menus Custom Menus
   Visual Basic
Visual Basic
   Resources
Resources on the Net
   Contact BigByte
Contact BigByte

Defined

DIESEL was introduced to AutoCAD users in AutoCAD R12 for DOS. DIESEL can return or pass string values to AutoCAD commands and return the value of any AutoCAD variable. DIESEL expressions can also return string values to the menu itself, altering the appearance and content of a menu label. In the absence of AutoLisp, DIESEL can be used to write simple macros for AutoCAD LT.

Listing of Functions

Function Syntax Description
+ (addition) (+,val1,val2,...valn) Returns the sum of the numbers val1, val2, ...valn.
- (subtraction) $(-,val1,val2,...valn) Returns the result of subtracting the numbers val2 through valn from val1
* (muliplication) $(*,val1,val2,...valn) Returns the result of multiplying the numbers val1,val2,...valn
/ (division) $(/,val1,val2,...valn) The result of dividing the number val1 by val2,...valn is returned.
= (equal) $(=,val1,val2) If the numbers val1 and val2 are equal 1 is returned,otherwise 0 is returned.
!= (not equal) $(!=,val1,val2) If the number val1 is greater than val2 1 is returned, otherwise 0 is returned.
< (less than) $(<,val1,val2) If the number val1 is less than val2 1 is returned, otherwise 0 is returned.
<= (less than or equal) $(<=,val1,val2) If the number val1 is less than or equal to val2 1 is returned, otherwise 0 is returned.
> (greater than) $(>,val1,val2) If the number val1 is greater than val2 1 is returned, otherwise 0 is returned.
>= (less than or equal) $(>=,val1,val2) If the number val1 is greater than or equal to val2 1 is returned, otherwise 0 is returned.
and $(and,val1,val2,...valn) The bitwise logical AND of the integers val1 through valn isreturned.
angtos $(angtos,value [,mode, precision]) Returns value as an angle in the format specified by mode and precision. Valid values for mode are:

0 = Decimal degrees
1 = Degrees/Minutes/Seconds
2 = Grads
3 = Radians
4 = Survayors units

If mode and precision are omitted the current values of AUNITS and AUPREC are used  

eq $(eq,val1,val2) If the strings val1 and val2 are identical 1 is returned,otherwise 0.
eval $(eval,str) The string str is passed to the DIESEL evaluator and the result of evaluating it is returned.
fix $(fix,value) Truncates the real number value to an integer by discarding any fractional part.
getenv $(getenv,varname) Returns the variable varname from the environment. If no such variable is defined, returns the null string.
getvar $(getvar,setting) Returns the value of the system variable setting
if $(if,expr,dotrue,dofalse) If expr is nonzero, dotrue is evaluated and returned. Otherwise, dofalse is evaluated and returned. Note that the branch not chosen by expr is not evaluated.
index $(index,which,string) String is assumed to contain one or more values delimited by themacro argument separator character, comma. The which argument selects one of these values to be extracted, with the first item numbered zero.

Use this function to extract x,y or z coordinates from a point value

linelen $(linelen) Returns the length, in characters, of the longest status line that the display can present to the user.
nth $(nth,which,arg0,arg1,argN) Evaluates and returns the argument selected by which. If which is 0, arg0 is returned, and so on.
or $(or,val1,val2,...valn) The bitwise logical OR of the integers val1 through valn is returned.
rtos $(rtos,value [,mode, precision]) Returns value as a rael number in the format specified by mode and precision. Valid values for mode are:

1 = Scientific 1.55E+01
2 = Decimal 15.50
3 = Engineering 1'-3.50"
4 = Architectural 1'-3 1/2"
5 = Fractional 15 1/2

If mode and precision are omitted the current values of LUNITS and LUPREC are used.

strlen $(strlen,string) Returns the length of string in characters.
substr $(substr,string,start[,length]) Returns the substring of string starting at character start and extending for length characters. Characters in the string are numbered from 1. If length is omitted, the entire remaining   length of the string is returned.
upper $(upper,string) The string is returned converted to upper case according to therules of the current locale.
xor $(xor,val1,val2,...valn) The bitwise logical XOR of the integers val1 through valn is returned.

Storing Variables

Storing Integers
Five AutoCAD system variables that have been included in the LT subset of system variables are the variables USERI1, USERI2.......USERI5. These variables are not mentioned in the AutoCAD LT Users Guide nor the Online Help. They are not used directly by the program and as such can be used to store any whole number between -32768 and 32767. The value is saved in the drawing and will persist between sessions.

Storing Real Numbers
Another five AutoCAD system variables that made it into LT are the variables USERR1, USERR2.......USERR5. Again they are not documented and can safely be used to store a number between 9.9E-99 and 9.9e+99. The value is saved in the drawing and will persist between sessions. 

Storing Strings
Unfortunately five variables that didn't make the transition to LT are the AutoCAD system variables USERS1-5 which can be used to store string variables. This was either an amazing lack of foresight on the behalf of AutoDesk or a deliberate (successful) attempt to limit the potential of LT thereby protecting AutoCAD's market.

What ever the case, we need to find another way to store string values. Fortunatly LT provides the command SETENV variablename myvalue which will create the string key variablename in the System Registry and assign it the value of myvalue. The command GETENV variablename can then be used to retrieve the value of variablename.

lt95.gif (363 bytes)
Earlier versions of AutoCAD LT saved this information in the [GENERAL] section of aclt.ini

Evaluation Sequence

If you start to write your own DIESEL macros sooner or later you will come across an extremely frustrating idiosyncrasy of the DIESEL macro language. That is the order in which DIESEL expressions are evaluated.

As an example lets look at how DIESEL evaluates the following macro

^C^C_id;\_setenv;pt1;$m=$(getvar,lastpoint);_line;$(getenv,pt1);\;

Looking at the above example one would expect it to be evaluated like this:

  • The _id command is issued with a backspace pausing the macro to allow the user to pick a point on the screen.
  • The _setenv command is then issued to save the value of the system variable lastpoint to a variable named pt1.
  • The _line command is the issued and the value of pt1 retrieved as the first point and another backspace pausing for the User to pick the second point.

What actually happens can be seen by setting the system variable macrotrace to 1 (on). This displays all DIESEL expressions and there results on the command line. This is what would be seen if the above macro was run with macrotrace on.

Command: _id
Point: X = 5.8769 Y = 6.1587 Z = 0.0000
Command: _setenv
Variable name: pt1
Value <6.22905364,5.59305622,0>: Eval: $(GETVAR, lastpoint)
===> 5.87689209,6.1586937,0
Eval: $(GETENV, pt1)
===> 6.22905364,5.59305622,0
5.87689209,6.1586937,0
Command: _line
From point: 6.22905364,5.59305622,0
To point:

What is all this telling us. Compare the co-ordinates returned by the _id command with the co-ordinates used as the from point in the _line command. It is a different point so what is going wrong.

Nothing! This is how DIESEL macros are evaluated by AutoCAD. Let me explain

  • The macro is copied directly to the command processor until the charactors '$m=' are encountered which indicates that a DIESEL expression follows. The remainer of the macro is passed to the DIESEL interpreter and evaluated and the result passed to the command processor
  • The end result is that value of pt1 as used by the _line command is returned BEFORE pt1 has been set to the value of lastpoint. In actual fact the first time you run a example macro it will fail altogather because pt1 has not been initialised and will return null

So if this is how DIESEL expressions are evaluated but it is not what we want what are we going to do about it. We enclose the second DIESEL function with quotes (") like so:

^C^C_id;\_setenv;pt1;$m=$(getvar,lastpoint);_line;"$m=$(getenv,pt1)";\;

the output with macrotrace on would now be

Command: _id
Point: X = 6.2291 Y = 6.1740 Z = 0.0000
Command: _setenv
Variable name: pt1
Value <11.69521383,5.71535621,0>: Eval: $(GETVAR, lastpoint)
===> 6.22905364,6.1739812,0
6.22905364,6.1739812,0
Command: _line
From point: Eval: $(GETENV, pt1)
===> 6.22905364,6.1739812,0
6.22905364,6.1739812,0
To point:

The addition of the pair of quotes prevents the DIESEL interpreter from evaluating the second expression. After evaluating the first expression the second expression is passed back to the command processor minus the pair of quotes. The command processor then continues with the _line command before the second '$m=' charactor sequence is encountered and the remainder of the macro is again passed the the DIESEL interpreter this time returning the new value of pt1

As a pair of quotes are discarded each time the macro is passed to the DIESEL interpreter each level of nesting requires an additional pair of quotes. Also you must preceed all nested DIESEL expressions with $m= to call the DIESEL interpreter unlike in the first example where the second DIESEL function opened with $(

Note: I do not pretend to be an expert on this subject as I still find it very difficult to get complex macros to be evaluated in the sequence desired. The evaluation sequence I have explained here is merely my observations and will gladly stand corrected if I anyone has a better explanation.

Getting User Input

Error Messages

If the DIESEL intepreter encounters an error whilst evaluating a macro it will embed an error message in the output string

Error Message Meaning
$? Syntax error such as a missing parenthesis
$(funcname,??) Incorrect arguments to funcname
$(funcname)?? Unknown function funcname
$(++) Output string to long

 


Copyright 1998 by BigByte Drafting.
All rights reserved.
Revised: 30 Dec 1999 20:30.