AfraLisp Blog

The AutoLisp/Visual Lisp/VBA Resource Website

AfraLisp Blog

Home Newsletter Utter Rubbish Coding Tips AutoCAD Tips Contact Downloads WAUN

Referencing DCL Files.

If you look in your AutoCAD Support directory, you will find a file entitled Base.Dcl. This file contains the DCL definitions for the basic, predefined tiles and tile types. It also contains definitions for commonly used prototypes.
You will also find Acad.Dcl in this directory. This file contains the standard definitions of all dialogue boxes used by AutoCAD.
But, did you know that a DCL file can also use tiles defined in another DCL file by naming the other file in what is called an include directory.
Let me try and show you how this works.

First create a new DCL file called Include1.Dcl:

include1 : dialog {

	label = "Choose a Point:";

	ok_cancel;

  		 }

 


Now, create a new AutoLisp file entitled Include1.Lsp with the following coding:
(defun c:include1 ()
;define the function

  (setq dcl_id (load_dialog "include1.dcl"))
  ;load the DCL file

  (if (not (new_dialog "include1" dcl_id))
  ;load the dialogue box

    (exit)
    ;if not loaded exit

  )

  (action_tile
    "cancel"
    "(done_dialog)
     (setq result nil)"
  )
  ;if Cancel button selected, close
  ;the dialogue.

  (action_tile
    "accept"

    "(done_dialog)
     (setq result T)"
  )
  ;if OK button was selected

  (start_dialog)
  ;start the dialogue

  (unload_dialog dcl_id)
  ;unload the dialogue

  (princ)

);defun

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


(princ);load clean

Open AutoCAD and load and run the routine.
You should have a very simple dialogue box looking like this :

Include Dialogue

Now, let's say we had a company logo, or something like that, that we wanted
to display on all our custom dialogue boxes. We could put the DCL coding for the logo in all our DCL files. But what happens, if say our telephone number changes. We would then have to edit all of our dialogue boxes containing the DCL coding for our logo. Here's a better way. We will create another DCL file containing the DCL coding for our logo, and include this file in our original DCL file. By doing it this way, we only have to change the master DCL file if we want to make revisions to our logo.

Let's create our logo DCL file first.
Create a new DCL file entitled Atitle.Dcl:

atitle : boxed_column {

	: paragraph {
	
		: text_part {
		  label = "Brought To";
		}
		
		: text_part {
		  label = " You By";
		}
		
		: text_part {

		  label = "AfraLisp";
		}

		: text_part {

		  label = "063-235837";
		}
	}
	
	}

Now revise the coding of our original include1.dcl to look like this:
@include "atitle.dcl"

include1 : dialog {

	label = "Choose a Point:";

	ok_cancel;

	atitle;

  		 }

Re-Load and run Include1.Lsp. It should look like this:

Include Dialogue

O.K I agree, it's not the best looking logo I've ever seen, but I'm sure you get the idea.

You can even include two or more references to DCL Files if you wish.
Let's have a look at another example. First create a new DCL file called gpoint.dcl. Add this coding to it:

gpoint	: boxed_column {
	  label = "Sample Point";

	: button {
	label = "Pick Point <";
	key = "hide";
	width = 12;
	fixed_width = true;
	mnemonic = "P";
	}

	: edit_box {
	key = "eb1";
	label = "&X:";
        width = 8;
	fixed_width = true;
	       	   }

	: edit_box {
	key = "eb2";
	label = "&Y:";
        width = 8;
	fixed_width = true;
	       	   }

	: edit_box {
	key = "eb3";
	label = "&Z:";
        width = 8;
	fixed_width = true;
	       	   }

	}

Now create a new DCL file entitle Include.Dcl and add this coding:
@include "gpoint.dcl"
@include "atitle.dcl"


include : dialog {

	label = "Choose a Point:";

	gpoint;

	ok_cancel;

	atitle;

  		 }

The coding for your lisp file, called Include.Lsp will look like this:
(defun c:include ()
;define the function

  (setq ptx "1.000"
	pty "0.000"
	ptz "0.000"
        flag 4
  );setq
  ;set default x,y, and z values
  ;and set flag to 4

  (setq dcl_id (load_dialog "include.dcl"))
  ;load the DCL file

  (while (> flag 2)
  ;check the flag status and carry on looping
  ;if it is greater than 2

  (if (not (new_dialog "include" dcl_id))
  ;load the dialogue box

    (exit)
    ;if not loaded exit

  )

  (set_tile "eb1" ptx)
  ;display x value

  (set_tile "eb2" pty)
  ;display y value

  (set_tile "eb3" ptz)
  ;display z value

  (mode_tile "eb1" 2)
  ;set focus to x edit box

  (mode_tile "eb1" 3)
  ;select contents

  (action_tile
    "cancel"
    "(done_dialog)
     (setq result nil)"
  )
  ;if Cancel button selected, close
  ;the dialogue. This action sets the
  ;flag to 0.

  (action_tile
    "accept"
    "(setq ptx (get_tile \"eb1\"))
     (setq pty (get_tile \"eb2\"))
     (setq ptz (get_tile \"eb3\"))
     (done_dialog)
     (setq result T)"
  )
  ;if OK button was selected, get the edit box
  ;point values, close the dialogue. This action
  ;sets the flag to 1.

  (action_tile
    "hide"
    "(done_dialog 4)"
  )
  ;if pick button selected, hide the dialogue
  ;and set the flag to 4

  (setq flag (start_dialog))
  ;start the dialogue and set flag
  ;to value of start dialogue
  
  (if (= flag 4)
  ;if the pick button was selected

    (progn
    ;do the following
	
      (setq selpoint (getpoint "\nInsertion Point: "))
      ;get the insertion point

      (setq ptx (rtos (car selpoint) 2 4))
      ;get the x value

      (setq pty (rtos (cadr selpoint) 2 4))
      ;get the y value

      (setq ptz (rtos (caddr selpoint) 2 4))
      ;get the z value

      
    );progn

  );if

  );while

  (unload_dialog dcl_id)
  ;unload the dialogue

  (princ)

);defun

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


(princ);load clean

Your dialogue box should look like this:

Include Dialogue

If you wanted, you could create a whole library of DCL files containing customised dialogue definitions which you could include/reference in all of your DCL files.


To download source coding for this Tutorial (27Kb) Click Here.
Sorry, not there, I mean here.

 
The AutoLisp/Visual Lisp/VBA Resource Website

Copyright © 1999-Perpetuity by AfraLisp

All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage

The AutoLisp/Visual Lisp/VBA Resource Website