Back HomeBack to DocumentsBack to D-I-E-S-E-LYou are here
DIESEL Programming Examples

DIESEL Programming Examples


VG-Wort Access-ZählmarkeAsks for a point, then moves this point to the X/Y plane by setting Z to zero.


Curved leader

Draws a curved leader. Uses a predefined block ARROW. There are two macros for left and right leaders.

[/CCurved leader right]^c^c_insert;arrow;\+
_text @$M=$(*,$(getvar,dimscale),$(getvar,dimgap))<0;+
[/uCurved leader left]^c^c_insert;arrow;\+
_text _r @$M=$(*,$(getvar,dimscale),$(getvar,dimgap))<180;+

Break Dline

Breaks a double line. Shows how to use a local coordinate system.

[Break DLine]+
^c^cmodemacro;Select first line:;+
modemacro;Select first break point:;+
modemacro;Select second break point:;+
modemacro;Select second line:;+

Break Dline2

Same, but uses local variables and trims.

[Break Dline2]+
^c^c_modemacro;Select first break point on first line;+
_modemacro;Select second break point on second line;+

Arc length

Displays the length of an arc. Demonstrates how to prompt for input.

[Arc length]+
_modemacro;Select arc:;+

Last edited

Places the date of the drawing's last modiffication on the drawing. There are two macros for US date format and international format.

[Last edited US]^c^c_text;$M=$(getvar,viewctr);;0;+
Last edited: $m=$(edtime,$(getvar,tdupdate),MO/DD/YY H:MM);+
modemacro;Enter date placement;+
[Last edited intl.]^c^c_text;$M=$(getvar,viewctr);;0;+
Last edited: $m=$(edtime,$(getvar,tdupdate),D.M.YY H:MM);+
modemacro;Enter date placement;+

A note on the TEXT command: Different versions of AutoCAD make different use of the TEXT command used to insert single-line text into a drawing. The macro shown will work without modification in AutoCAD up to Release 14 and LT up to LT 98. In AutoCAD (LT) 2000i you need to use the command -TEXT (with a leading dash) instead. In AutoCAD (LT) 2000 neither one works. There my advice is to update to the i versions. If you don't want to, you need to use an attributed block or the command line version of the paragraph text command (-MTEXT) to place text in a drawing.

Rotated Copy

Places a rotated copy of selected entities.


Align objects

This emulates the ALIGN command found in full AutoCAD. Select the objects to align, then in sequence: a point on the objects to align, the target point where this point is going to land, a second point on the objects to align, the target point where this point is going to land. If the distances differ, the second target point only defines the direction, not any scaling.


Half a line

Asks for two points, then draws a line from first point half the distance to the second point. Demonstates delaying of DIESEL evaluation.

[Half a line]+


Draws a number with every pick and automatically increments it. Uses style, height and rotation of last drawn text. Setvar start value as USERI1.


Please read the note on the TEXT command as well.

Insert Area value

Inserts the area of any previously measured object/area as text into the drawing. This macro needs a block named AREABLK located in the current drawing, the template drawing or anywhere on AutoCAD's search path. AREABLK has to have exactly one attribute which will be filled with the area value.


In-the-middle-of Snap

Demonstrates how to write a macro that runs transparently within any other command. This one calculates the midpoint between two points selected, e.g. the center of a rectangle. Uses LIMMIN and LIMMAX which are 2D points.


Dimension an arc's length

This macro was written by Erik Verbeeck. It dimensions an arc using the arc's length instead of the included angle.


Text on Arc

Below is a very complex DIESEL macro, written by Robert Freeman. It demonstrates several useful programming techniques, most importantly it demonstrates how to create loops in DIESEL. You will need some time to study how this macro works (as did I), but it's worth the effort. Some hints: Watch for ct1 and ct2. ct1 is a flag which lets the macro run through a couple of alternatives, ct2 is a counter which loops from 1 to the end of the string to write. Many thanks to Robert Freeman for posting this code in the AutoCAD LT newsgroup. We tried to get an explicit permission from him to re-post it here, but unfortunately the email address listed in the comments does not work any more. Robert, if you're listening, please contact me at

Please read the note on the TEXT command as well.

[Text on Arc]
//This is a partial menu file that contains a macro to wrap text around an arc.  It
//prompts for two points and a text string, and then pops up a cursor menu asking
//how you want the text orientated.
//This macro was developed in and for AutoCAD LT 97.  It may also work in earlier
//versions but has not been tested in them.
//Robert Freeman
//Please consult your AutoCAD LT 97 documentation for instructions on installing
//partial menu files.  Only insert the menu entitled "Text on Arc".  Do not insert
//the menu entitled "Cursor".
//Before you begin
//        1.  Before you can begin using the "Text on Arc" macro you must first select
//            "Reset" from the "Text on Arc" menu item.  This creates and sets a number of
//            environmental variables needed by the "Text on Arc" macro.  You only have to do
//            this the first time you use the macro.
//        2.  This macro assumes that the current text style is set to a fixed text height and that
//            text height is equal to the "TEXTSIZE" system variable.  If the current
//          text style text height is set to 0, this macro will fail.  The "Reset" macro
//            will prompt for this value and will change both the current setting of the "TEXTSIZE"
//            system variable and the text height of the current text style. Search AutoCAD LT help for
//          the STYLE command if you don't understand this.  Also, the text size is assumed to be
//            at full scale.
//        3.  This macro makes use of the PSPROLOG system variable for text entry.  This
//            variable is used by AutoCAD LT to assign a name for a prolog section to be read
//            from the aclt.psf file when using the PSOUT command.  Its default value is "".
//            If you do not export encapsulated PostScript (ESP) files, this should not cause you
//            any problems.  If you do use ESP files and PSPROLOG normally is set to some value,
//            you should check to be sure that its value is set correctly before you use the PSOUT
//            command.  You can do this by selecting the Options button in the PSOUT dialog box.
//            The macro does attempt to store and reset this value, however if the macro is cancelled
//            prematurely, this value may be lost.
//Using the "Text on Arc" macro.
//        1.  Select "Text on Arc" from the ArcText menu.
//        2.  You will be prompted for the center point of the arc you want your text to wrap around.
//        3.  Next select the middle point of your text.
//        4.  You will then be prompted to enter a text string.  Enter your text string and press enter.
//        5.  A cursor menu will then pop up with two items - "Bottom of text points toward the radius" and
//            "Bottom of text points away from the radius.  Select one.  Note: If the length of your text
//            string exceeds the circumference of a circle drawn around the radius point you selected, you
//            will receive the error message "Text string too long."  Try again using a shorter text string
//            or select a middle point farther away from your center point.
//        6.  Although the macro is entitled "Text on Arc", you do not have to select the center of
//            an actual arc.  Any point will do.  The arc the text wraps around is calculated using the
//            distance between the two points you select as the radius.
//        7.  An UNDO with the BACK option will delete your text if you make an error.
//Known issues
//        1.  If you cancel the macro before it completes, the macro probably won't work correctly the
//            next time you use it.  Select "Reset" from the menu to correct for this situation.
//        2.  Even though the system variable MENUECHO is set to 3 (suppress everything possible), you
//            may see extra text after the various prompts.  In particular, you may see the text "ID"
//            when the macro prompts for the center point.  Although it makes the prompts look bad, it
//            does not cause any problems.  Unfortunately, this does not happen every time. This has
//            made it difficult to find a solution.
//        3.  If you enter a text string with a single quotation mark followed by a space, all characters
//            from the quotation mark to the end of the string will be truncated.  For example if you enter
//            the string Delta=90d00'00" Radius=10,  it will be truncated to Delta=90d00'00.  The work
//            around is to replace the space after the single quotation mark with a dummy character and then
//            erase it afterwards.
//        4.  If you decide to add your own enhancements to this macro, be aware that there is an apparent
//            bug in ACAD LT 97's menu interpreter that causes ACAD LT 97 to crash if the number of characters
//            under a label exceeds about 2200 characters.  Tech support confirmed to me that this is a problem
//            [they duplicated the situation on their PC's] but unfortunately they said they have no plans
//            to issue a patch for this problem.
//Environmental variables used
//cd  = character delta - central angle in radians of a single character's arc length
//cps = current psprolog setting - saves users current psprolog setting
//csm = current snap mode - saves users current Osmode setting
//ct1 = counter number 1
//ct2 = counter number 2
//ern = error number - Used to determine if an error occurs
//er2 = error message 2 - "Text string is too long."
//er3 = error message 3 - "Radius cannot equal 0."
//mb  = midpoint bearing - Direction from pt1 to pt2
//ob  = offset bearing - Direction from radius to middle point of each character
//pm3 = prompt 3 - "Enter center point of arc:"
//pm7 = prompt 7 - "Enter middle point of text:"
//pm6 = prompt 6 - "Enter text: "
//pm8 = prompt 8 - "Enter text size. Value MUST equal current style text height setting:"
//pmb = prompt b = Concatenation of variable pm8 and current setting of the system variable "textsize".
//pt1 = point number 1 - Center point of arc
//pt2 = point number 2 - Middle point of text
//qt  = quotation mark - "
//rd  = radius = Distance from pt1 to pt2
//sb  = start bearing - Direction from radius to middle point of first character
//st  = string value - Text string to be arced
//sl  = string length - Number of characters in st
//tb  = text bearing - Rotation angle of each character of text
//td  = text delta - Central angle in radians of st arc length
//tl  = text length - Arc length of st
//System variables used
//osmode - Set to 0.  Users current settings are saved and reset
//menuecho - Set to 3 to suppress everything possible.  Reset to 0 at end of macro.
//lastpoint - Used to set pt1 and pt2
//distance - Used to set rd
//chamferd - Used to set mb
//psprolog - Used to retrieve text string.  Used because it is one of the few
//             system variables that will accept embedded spaces and punctuation.
//             Users settings are saved and reset.
SETENV;er2;"Text string is too long.";+
SETENV;er3;"Radius cannot equal 0.";+
SETENV;pm3;"Enter center point of arc:";+
SETENV;pm7;"Enter middle point of text:";+
SETENV;pm6;"Enter text:";+
SETENV;pm8;"Enter text size. This will change current style text height setting.";+

[Text on Arc]*^C^C+
$P0=ArcText.Cursor $P0=*)+



[Bottom of text points toward Radius]*^C^C+

[Bottom of text points away from radius]*^C^C+

This is a shareware document. What is a shareware document? Did this article help you earn some money? Then give something back! Help creating shareware documents by donating something to the author:

Contact CR/LF GmbH

© 2000-2011 by CR/LF GmbH, Essen/Germany. All rights reserved.
No part of this document may be reproduced or published without written consent by CR/LF GmbH.
Last modification: 01.04.2011