AfraLISP - Learn AutoLISP for AutoCAD productivity

Drawing Setup - Part 1

by Kenny Ramage

This to me, is the one area that all AutoLispers, especially AutoLISP beginners, should be spending their time and energy. A good, well written setup routine can saves hours of draughting time, as well as enforcing drawing office standards.

This tutorial will take you step by step through a simple drawing setup routine which, I hope, you will be able to build on to suit your requirements.

We will start by designing a dialogue interface to choose the type of drawing sheet the draughtsman would like to use. Let's look at the coding for the dialogue box :

setup1 : dialog {				//dialogue name
        label = "Initial Drawing Setup";	//label
      : boxed_radio_column {			//start radio column
        label = "Choose Sheet";			//label
        : radio_button {			//radio button
          label = "&Engineering Sheets";	//label
          key = "rb1";				//key
          value = "1";				//make it default
        }					//end radio button
        : radio_button {			//another radio button
          label = "&Architectural Sheets";	//label
          key = "rb2"; 				//key
        }					//end radio button
        : radio_button {			//another radio button
          label = "&Civil Sheets";		//label
          key = "rb3"; 				//key
        }					//end radio button
        : radio_button {			//another radio button
          label = "&Electrical Sheets";		//label
          key = "rb4"; 				//key
        }					//end radio button
        : radio_button {			//another radio button
          label = "&Blank Sheets";		//label
          key = "rb5"; 				//key
        }					//end radio button
      }						//end radio column
        ok_cancel ;				//OK/Cancel Tile
        : paragraph {				//begin paragraph
	   : text_part {			//a bit of text
             label = "Designed and Created";	//text
           }					//end text
           : text_part {			//another bit of text
             label = "by Kenny Ramage";		//credits
           }					//end text
        }					//end paragraph
      }						//end dialogue

Now, let's write some lisp to display the dialogue box :

(defun C:SETUP1 ()				;define function
     (setvar "BLIPMODE" 0)			;switch off variables
     (setvar "CMDECHO" 0)
     (setvar "OSMODE" 0)
     (setq typ "e")				;set default
     (setq dcl_id (load_dialog "setup1.dcl"))	;load dialogue
     (if (not 					;test if loaded
           (new_dialog "setup1" dcl_id)		;new dialogue
         )					;end not
           (exit)				;if not loaded, exit
     )						;end if
     (set_tile "rb1" "1")			;switch on radio button
     (action_tile "rb1"				;if button selected
         "(setq typ \"e\")")			;store sheet type
     (action_tile "rb2"				;if button selected
         "(setq typ \"a\")")			;store sheet type
     (action_tile "rb3"				;if button selected
         "(setq typ \"c\")")			;store sheet type
     (action_tile "rb4"				;if button selected
         "(setq typ \"el\")")			;store sheet type
     (action_tile "rb5"				;if button selected
         "(setq typ \"b\")")			;store sheet type
     (action_tile "cancel"			;if Cancel selected
         "(done_dialog)(setq userclick nil)")	;close dialogue, clear flag
     (action_tile "accept"			;if OK selected
         "(done_dialog) (setq userclick T)")	;close dialogue, set flag
     (start_dialog)				;start dialogue
     (unload_dialog dcl_id)			;unload dialogue
 (princ)					;finish clean
)						;end function
(princ)

Your dialogue box should look like this :

Setup1

We've now designed a dialogue box that enables us to choose the type of drawing sheet that we would like to use. But, we still need to be able to choose the size of sheet and the scale that we would like to draw with. Let's modify our dialogue box and add these functions :

Note : New lines of code are highlighted.

setup2 : dialog {				//dialogue name
        label = "Initial Drawing Setup";	//label
      : row {					//start row
      : boxed_radio_column {			//start radio column
        label = "Choose Sheet";			//label
        : radio_button {			//radio button
          label = "&Engineering Sheets";	//label
          key = "rb1";				//key
          value = "1";				//make it default
        }					//end radio button
        : radio_button {			//another radio button
          label = "&Architectural Sheets";	//label
          key = "rb2"; 				//key
        }					//end radio button
        : radio_button {			//another radio button
          label = "&Civil Sheets";		//label
          key = "rb3"; 				//key
        }					//end radio button
        : radio_button {			//another radio button
          label = "&Electrical Sheets";		//label
          key = "rb4"; 				//key
        }					//end radio button
        : radio_button {			//another radio button
          label = "&Blank Sheets";		//label
          key = "rb5"; 				//key
        }					//end radio button
      }						//end radio column
     : boxed_radio_column {			//start radio column
      label = "Choose Size :";			//label
        : radio_button {			//radio button
          label = "A&0 - 1189 x 841";		//label
          key = "rb6";				//key
          value = "1";				//make it default
        }					//end radio button
        : radio_button {			//radio button
          label = "A&1 -   841 x 594";		//label
          key = "rb7"; 				//key
        }					//end radio button
        : radio_button {			//radio button
          label = "A&2 -   594 x 420";		//label
          key = "rb8"; 				//key
        }					//end radio button
        : radio_button {			//radio button
          label = "A&3 -   420 x 297";		//label
          key = "rb9"; 				//key
        }					//end radio button
        : radio_button {			//radio button
          label = "A&4 -   297 x 210";		//label
          key = "rb10";				//key
        }					//end radio button
      }						//end radio column
      }						//end row
        : edit_box {				//start edit box
          label = "&Enter Drawing Scale :" ;	//label
          key = "eb1" ;				//key
          edit_width = 8 ;			//width of box
        }					//end edit box
        :spacer { width = 1;}			//spacer
        ok_cancel ;				//OK/Cancel Tile
        : paragraph {				//begin paragraph
	   : text_part {			//a bit of text
             label = "Designed and Created";	//text
           }					//end text
           : text_part {			//another bit of text
             label = "by Kenny Ramage";		//credits
           }					//end text
        }					//end paragraph
      }						//end dialogue

And now the Autolisp Coding :

(defun C:SETUP2 ()				;define function
     (setvar "BLIPMODE" 0)			;switch off variables
     (setvar "CMDECHO" 0)
     (setvar "OSMODE" 0)
     (setq typ "e")				;set default
     (setq dcl_id (load_dialog "setup2.dcl"))	;load dialogue
     (if (not 					;test if loaded
           (new_dialog "setup2" dcl_id)		;new dialogue
         )					;end not
           (exit)				;if not loaded, exit
     )						;end if
     (set_tile "rb1" "1")			;switch on radio button
     (action_tile "rb1"				;if button selected
         "(setq typ \"e\")			;store sheet type
          (mode_tile \"eb1\" 2)")		;set focus to edit box
     (action_tile "rb2"				;if button selected
         "(setq typ \"a\")			;store sheet type
          (mode_tile \"eb1\" 2)")		;set focus to edit box
     (action_tile "rb3"				;if button selected
         "(setq typ \"c\")			;store sheet type
          (mode_tile \"eb1\" 2)")		;set focus to edit box
     (action_tile "rb4"				;if button selected
         "(setq typ \"el\")			;store sheet type
          (mode_tile \"eb1\" 2)")		;set focus to edit box
     (action_tile "rb5"				;if button selected
         "(setq typ \"b\")			;store sheet type
          (mode_tile \"eb1\" 2)")		;set focus to edit box
 
     (set_tile "rb6" "1")			;make default
     (set_tile "eb1" "1")			;initial edit box value
     (mode_tile "eb1" 2)			;set focus to edit box
     (action_tile "rb6"				;if button selected
         "(setq siz \"A0\")			;store sheet size
          (mode_tile \"eb1\" 2)")		;set focus to edit box
     (action_tile "rb7"				;if button selected
         "(setq siz \"A1\")			;store sheet size
          (mode_tile \"eb1\" 2)")		;set focus to edit box
     (action_tile "rb8"				;if button selected
         "(setq siz \"A2\")			;store sheet size
          (mode_tile \"eb1\" 2)")		;set focus to edit box
     (action_tile "rb9"				;if button selected
         "(setq siz \"A3\")			;store sheet size
          (mode_tile \"eb1\" 2)")		;set focus to edit box
     (action_tile "rb10"			;if button selected
         "(setq siz \"A4\")			;store sheet size
          (mode_tile \"eb1\" 2)")		;set focus to edit box
 
     (action_tile "cancel"			;if Cancel selected
         "(done_dialog)(setq userclick nil)")	;close dialogue, clear flag
     (action_tile "accept"			;if OK selected
       (strcat					;string 'em together
      "(progn (setq #dwgsc			;store value
              (atof (get_tile \"eb1\")))"	;get edit box value
            "(done_dialog) (setq userclick T))" ;close dialogue, set flag
       )					;end progn
     )						;end action_tile
 
     (start_dialog)				;start dialogue
     (unload_dialog dcl_id)			;unload dialogue
 (princ)					;finish clean
)						;end function
(princ)

Here's what your dialogue should look like :

Setup2

We've now completed our dialogue box. In Part 2 we'll try and get it to do something. See you there…