AfraLisp Blog

The AutoLisp/Visual Lisp/VBA Resource Website

AfraLisp Blog

Home Newsletter Utter Rubbish Coding Tips AutoCAD Tips Contact Downloads WAUN

AutoLisp/VBA Drawing Setup

A well written drawing setup routine can save hours in any drawing office and is invaluable when it comes to enforcing drawing office standards. There is nothing worse than a drawing office where everybody "does there own thing" in regards to drawing setups. As well as this, a setup routine and template drawings/drawing sheets can be given to third party companies to ensure that they comply with your standards and specifications. This month we're going to have a look at a simple but powerful setup routine first written in plain old AutoLisp and then written using the Dark Side - otherwise known as VBA for the uninitiated. Let's have a look at the program in action :

Usage :

Select your Drawing Sheet type first, then the Drawing Size, select a Scale and then the OK button and away you go.

To use your own drawing sheets in this routine, please refer to the Readme file which is included within the downloadable drawing sheet zip file. (The download link is at the bottom of the next page - hey, we have to make sure you read everything.)


This program not only inserts a chosen type and size of drawing sheet into your drawing, but also sets your text height and dimension scaling to suit the scale factor.
You can even preset your own system variables within the program. Go for it, it's yours for ever and ever to do with as you wish.

First the DCL coding.
Copy and paste this into Notepad and save it as "ALSetup.dcl."


alsetup : dialog {
        label = "CAD Encoding Drawing Setup";

      : row {

      : boxed_radio_column {
        label = "Choose Sheet";

        : radio_button {
          label = "&Engineering Sheets";
          key = "rb1";
          value = "1";
        : radio_button {
          label = "&Architectural Sheets";
          key = "rb2"; 
        : radio_button {
          label = "&Electrical Sheets";
          key = "rb4";
        : radio_button {
          label = "&Blank Sheets";
          key = "rb5"; 

     : boxed_radio_column {
      label = "Choose Size :";

        : radio_button {
          label = "A&0 - 1189 x 841";
          key = "rb6";
          value = "1";
        : radio_button {
          label = "A&1 -   841 x 594";
          key = "rb7"; 
        : radio_button {
          label = "A&2 -   594 x 420";
          key = "rb8"; 
        : radio_button {
          label = "A&3 -   420 x 297";
          key = "rb9"; 
        : radio_button {
          label = "A&4 -   297 x 210";
          key = "rb10";

        : edit_box {
          label = "&Enter Drawing Scale :" ;	
          key = "eb1" ;	
          edit_width = 8 ;

        :spacer { width = 1;}

        ok_cancel ;

        : paragraph {

	   : text_part {
             label = "Designed and Created";

           : text_part {
             label = "by CAD Encoding";




And next, here's the AutoLisp coding. No Visual Lisp this time, just plain AutoLisp. ("Phew," I can hear a lot of you saying, wiping your delicate brows in relief.)
Copy and paste this into Notepad and save it as "ALSetup.lsp."


(prompt "\nCAD Encoding Setup loaded - Type \"ALSETUP\" to run....")

(defun C:ALSETUP ( / userclick dcl_id siz typ x y l size n oldblip
                                    oldecho oldsnap #dwgsc)

     ;save system settings
     (setq oldblip (getvar "BLIPMODE")
             oldecho (getvar "CMDECHO")
             oldsnap (getvar "OSMODE")

     ;set system variables
     (setvar "BLIPMODE" 0)
     (setvar "CMDECHO" 0)
     (setvar "OSMODE" 0)

     ;load the dialog
     (setq dcl_id (load_dialog "alsetup.dcl"))
     (if (not (new_dialog "alsetup" dcl_id))

     ;define default settings
     (set_tile "rb1" "1")
     (set_tile "rb6" "1")
     (set_tile "eb1" "1")
     (setq siz "A0")
     (setq typ "e")

     ;define radio buttons action statements
     (action_tile "rb1" "(setq typ \"e\")  (mtile)")
     (action_tile "rb2" "(setq typ \"a\")  (mtile)")
     (action_tile "rb4" "(setq typ \"el\") (mtile)")
     (action_tile "rb5" "(setq typ \"b\")  (mtile)")

     (action_tile "rb6" "(setq siz \"A0\") (mtile)")
     (action_tile "rb7" "(setq siz \"A1\") (mtile)")
     (action_tile "rb8" "(setq siz \"A2\") (mtile)")
     (action_tile "rb9" "(setq siz \"A3\") (mtile)")
     (action_tile "rb10" "(setq siz \"A4\") (mtile)")

     ;define Cancel action statements
     (action_tile "cancel"
         "(done_dialog)(setq userclick nil)")

     ;define OK action statements
     (action_tile "accept"
      "(progn (setq #dwgsc (atof (get_tile \"eb1\")))"
            "(done_dialog) (setq userclick T))"

     ;display the dialog

     ;unload the dialog
     (unload_dialog dcl_id)

;check the flag setting
(if userclick

    ;if it's set, do the following

    ;set up the sheet size

      ((= siz "A0") (setq x 1189.0 y 841.0))
      ((= siz "A1") (setq x 841.0 y 594.0))
      ((= siz "A2") (setq x 594.0 y 420.0))
      ((= siz "A3") (setq x 420.0 y 297.0))
      ((= siz "A4") (setq x 297.0 y 210.0))

    ;Construct drawing sheet name
     (setq size (strcat typ siz))

      ;set system variables according to scale
      (setvar "DIMSCALE" #dwgsc)
      (setvar "USERR1" #dwgsc)
      (setvar "LTSCALE" (* #dwgsc 10))
      (setvar "REGENMODE" 1)
      (setvar "TILEMODE" 1)
      (setq n (* 3.5 #dwgsc))

      ;define the limits list
      (setq L (list (* x #dwgsc) (* y #dwgsc)))

      ;set up the drawing
      (command "LIMITS" "0,0" L 
                       "ZOOM" "W" "0,0" L
	           "STYLE" "italict" "italict" N "" "" "" "" ""
                       "INSERT" size "0,0" #dwgsc "" "" )

        ;inform the user
        (prompt "\n ")
        (prompt "\nOkay - Setup Routine Complete")


  ;reset system variables
  (setvar "BLIPMODE" oldblip)
  (setvar "CMDECHO" oldecho)
  (setvar "OSMODE" oldsnap)

 ;finish clean


;function to set the focus to
;the scale edit box
(defun mtile ()

(mode_tile "eb1" 2)


;load clean


Store both files and the drawing sheet files in a directory within your AutoCAD search path. Now type (load "ALSetup") at the AutoCAD command prompt, and then "ALSetup" to run the setup program.

On the next page we'll have a look at doing the same thing using VBA, but this time we'll make use of drawing template files.

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