Our Friends: Leaflet Printing , Presented by: Talia Cad Software

Sign In

Subscribe

Subscribe to Daily Autocad.


Oct 23
Tuesday
AutoLISP, Autocad, DCL, Programming
Programming dialog boxes in AutoLISP: DCL

All VisualLISP versions

Hello Daily AutoCAD readers,

After a long period of time, I am back again with this article about AutoLISP. Today’s subject is to give an example function for dialog box programming by using DCL dialog control language. DCL:GETINT function prompts from the user to enter an integer (Fig. 1). Program is prepared in a portable manner. It can be used as a library for those who are interested in LISP programming language.

Fig.1
Fig.1 – DCL – Dialog Box

In order to run DCL:GETINT function, we need 6 arguments. You have to pass all of the arguments while running the function, which means that you must assign the unneeded arguments as Nil.

  1. Title“: Name of the window; it is the name that is seen in the title bar when the dialog box is opened. Data type is ‘STR‘ (String).
  2. Prompt“: The message that is prompted to the user. Data type is ‘STR‘ (String)
  3. Flag” Separately from the other arguments, some additional control purpose is assigned to this argument.
    1. Bit 1 = Does not accept empty value.
    2. Bit 2 = Zero values are not accepted
    3. Bit 4 = Values smaller than zero (negative) are not accepted.
    4. Data type is ‘INT (Integer ) or Nil if not needed.
  4. Default“: A default starting value is assigned. For example, final entered value is reminded to the user. Data type is ‘INT‘ (Integer ) or Nil if not needed.
  5. Max“: It determines the maximum number of integers that the user can enter Data type is ‘INT‘ (Integer ) or Nil if not needed.
  6. Min“: It determines the minimum number of integers that the user can enter Data type is ‘INT‘ (Integer ) or Nil if not needed.

(DCL:GETINT “ENGINE” “1. gear” nil nil nil nil)
(It is prompted from the user to enter any integer without any restrictions)

(DCL:GETINT “ENGINE” “1. gear” nil 4 20 5)
(Default value is 4. It is prompted from the user to enter any integer between 5 and 20.)

(DCL:GETINT “ENGINE” “2. gear” 6 nil nil nil)
(All of the values can be entered except zero and smaller than zero)

We will also need global variables in these functions, just like we need them in other programs. As it can be understood from its name; global variables are the variables that can be directly accessed from anywhere inside the program. In order to define a variable in global level, we are using GLV: prefix. If you examine the AutoLISP file carefully, you will notice that (DCL:INIT:GLOBAL:VALUE)has been added at the end of the file (Fig. 2). By this way, as soon as the AutoLISP file is loaded, this file will automatically be loaded and the variables that is included in it are initialized.

Fig.2
Fig.2 – Sub function “UTL:INIT:GLOBAL:VALUE“

DCL:GETINT-TEST function (Fig.3) tests the program.

Fig.3
Fig.3 – Main function “C:DCL-GETINT-TEST” or “C:X“

DCL:GETINT function (Fig.4) forms up the basis of the program. Name of the dialog control is located inside the dcl_name variable as “KML_EDITBOX” (1). Dialogs forms up mosaic shapes that are called tiles. Similar to using bricks to construct a building, you need these labels to construct a dialog box. In order to access these labels, you must give a name (key). You can separate these variables from the other variables by assigning key: prefix to these variables (2).

Fig.4-1
Fig.4-2
Fig.4-3
Fig.4 – Sub function “DCL:GETINT“

DCL:USER:INPUT:INTEGER function (Fig.5) controls if the entered variables are valid according to required criterions. These criterions depend on how the program is called, thus the arguments.

Fig.5
Fig.5 – Sub function “DCL:USER:INPUT:INTEGER“

DCL:USER:CHECK:IS:NUMERIC function (Fig.6) controls if the values that were entered are only made up of numbers. If the entry is not valid, then the entered value is deleted and prompted to be entered again.

Fig.6
Fig.6 – Sub function “DCL:USER:CHECK:IS:NUMERIC“

DCL:USER:CHECK:FLAG function (Fig.7) controls if the entered value is empty, zero or larger than zero.

Fig.7
Fig.7 – Sub function “DCL:USER:CHECK:FLAG“

DCL:USER:CHECK:MIN-VALUE function (Fig.8) controls if the entered value exceeds the minimum limit. Other vise, the unaccepted value is removed from the value input box and the user is prompted to enter from the beginning.

Fig.8
Fig.8 – Sub function “DCL:USER:CHECK:MIN-VALUE“

DCL:USER:CHECK:MAX:VALUE function (Fig.9) controls if the entered value exceeds the maximum limit. Otherwise, the unaccepted value is removed from the value input box and the user is prompted to enter from the beginning.

Fig.9
Fig.9 – Sub function “DCL:USER:CHECK:MAX-VALUE“

DCL:SET:DIALOG function (Fig.10) determines the user interface file that has .dcl extension to AutoCAD system. If the file is not found, it gives an error and stops the program by vl-exit-with-value command. In general, AutoCAD searches among “Support file search path” part. By using tools->options in AutoCAD, you can see the folders that were defined.

Fig.10
Fig.10 – Sub function “UTL:SET:DIALOG“

DCL:LOAD:DIALOG function (Fig.11) loads the user interface file that has .dcl extension to AutoCAD system. If the file is not found, it gives an error and stops the program by vl-exit-with-value command. In general, AutoCAD searches among “Support file search path” part. By using tools->options in AutoCAD, you can see the folders that were defined.

Fig.11
Fig.11 – Sub function “UTL:LOAD:DIALOG“

UTL:IS:NUMERIC function (Fig.12) controls if data entered by the user is composed of numbers only. It returns the value of T if entered as numbers or Nil other vise. These values are Boolean value types. T means TRUE, which is 1. And Nil (Not in List) is generally used in AutoLISP language and it means FALSE or 0.

Fig.12
Fig.12 – Sub function “UTL:IS:NUMERIC“

Fig.13
Fig.13 – Dialog Control Language “DCL-GETINT.dcl“

DCL commands that are used in the program:

  • new_dialog
  • load_dialog, unload_dialog
  • start_dialog
  • set_tile

I am looking forward to hear from your questions about the subject. You can download file from here.

Have a nice day.

Related Articles: AutoLISP page, VisualLISP page

Technorati Tags: , ,

Read in other languages: TR

Viewed 9,982 times so far... This week: 124 Today: 6 Latest: 5 July 2009, 3:32

Post Tags:

13 Responses to “ Programming dialog boxes in AutoLISP: DCL ”
  1. In case your readers are not aware, there is a free open source replacement for DCL called OpenDCL (http://www.opendcl.com) that offers much more advanced capabilities and is easier to use than the built in DCL implementation. I hope the contributors to this excellent blog will consider writing about OpenDCL in a future article. :)

  2. Hi Owen,

    It’s a great pleasure to see your comment in Daily AutoCAD again. I think the best article about OpenDCL can be written by you :) . We’re waiting your article about OpenDCL.

  3. Orhan, I will see what I can do. First I need to get OpenDCL 4.0 released!

  4. hi,
    i dont know anything about dcl.i m first trying to modify one dcl file i got from internet.i can move buttons as i wish.thats what i learnt.
    it displays blocks from .slb files in tiles.i just want to add name of the block(file) below it.how to do it?
    any help is appreciated
    thanx

  5. I have created 2d piping reducers and other 2d piping symbols and would like to have them into a lips file so i can insert them. I purchase a DLC and lisp program but i’m still learning autolisp. I wish there was a lisp book that took you step by step or a book for dummys.
    I have been customizing AutoCAD menu for year with menu commands and scripts file but never lisp files.
    how much work is it to create DLC and Lisp file to do what i’m looking for!
    or is there a lisp file ouyt there i can modify. I want to learn but trying to find the time and a good book that will be every basic to i can learn.

  6. Muharrem Kocyigit

    Nov 21, 2007
    Reply

    Hi Curt,

    “AutoCAD Developer’s Guide to Visual LISP” is a good book (Author Nikolai Poleschuk)
    http://www.amazon.de/AutoCAD-Developers-Guide-Visual-LISP/dp/1584500913/

    Thank you for your visit

  7. Hello, Ls & Gs

    can anyone give me some suggestion.

    You know there is a commnad “color” in Autocad, and when we picked a specified color, the color will be shown on the bottom right of the dialoge box.

    I want to call this command and the the returned. I want to set some tile in my DCL and the the color of the tile could be changed based on what returned from that “color” command. What kind of tile should that be, and how to change the color of that tile accordingly.

    Thanks in advance.

  8. can you help me or show me how to write a program (autolisp) to shown/display the coordinates XYZ on the autocad drawing with just select the point.

    thanks

  9. A bit of a basic question here:
    Just starting out with lisp and dcl. I have a working lisp that references a dcl (E:sample7.dcl) from a tutorial – when run, it cant find the dcl – where should I be placing this file? If not in e:\?

  10. Muharrem Kocyigit

    Aug 27, 2008
    Reply

    Hi Drano,

    The function findfile makes possible to find necessary file for you. Searches the AutoCAD library path for the specified file or directory.

    Example:

    (if (setq ff (findfile “test.dcl”)) (progn ….any-code… ))

  11. Muharrem Kocyigit

    Aug 27, 2008
    Reply

    Hi cnt,

    Here is the solution (Lisp-Code):


    (defun c:pp ( / ss n pt )
    (setq n 0)
    (if (setq ss (ssget (list (cons 0 "POINT"))))
    (while (< n (sslength ss))
    (setq pt (cdr (assoc 10 (entget (ssname ss n)))))
    (mapcar 'princ (list
    "\n"
    "X=" (car pt) " "
    "Y=" (cadr pt) " "
    "Z=" (cadr pt)
    ))
    (setq n (1+ n))
    )
    )
    (princ)
    )

  12. thanks for your reply

    however,,,, i have try but the z value is wrong???
    i need the display on the drawing not on the command line.
    thanks for your solution…


Post a Comment



All content and source © 2008 Daily Autocad | News Plus wordpress theme brought to you by Zidalgo.