AfraLisp Blog

The AutoLisp/Visual Lisp/VBA Resource Website

AfraLisp Blog

Home Newsletter Utter Rubbish Coding Tips AutoCAD Tips Contact Downloads WAUN

Page I. Home. Page III.

Drawing Setup Tutorial - Page II.

As you can see from the dialogue box, we have 5 different types of drawing sheets and 5 sizes. Because of space constraints, I cannot post all 25 template drawings.
Therefore, I will only supply the 5 Blank drawing templates.
All of the template drawings should be named thus :

Engineering Drawings 

  • EA0.DWG
  • EA1.DWG
  • EA2.DWG
  • EA3.DWG
  • EA4.DWG
Architectural Drawings 
  • AA0.DWG
  • AA1.DWG
  • AA2.DWG
  • AA3.DWG
  • AA4.DWG
Civil 
  • CA0.DWG
  • CA1.DWG
  • CA2.DWG
  • CA3.DWG
  • CA4.DWG
Electrical Drawings 
  • ELA0.DWG
  • ELA1.DWG
  • ELA2.DWG
  • ELA3.DWG
  • ELA4.DWG
Blank Drawings 
  • BA0.DWG
  • BA1.DWG
  • BA2.DWG
  • BA3.DWG
  • BA4.DWG
I will leave it up to you to produce the rest of the template drawings.
For your information, here is the dimensions of the most common Metric Drawing Sheets : 
A0 - 1189 mm x 841 mm
A1 -  841 mm x 594 mm
A2 -  594 mm x 420 mm
A3 -  420 mm x 297 mm
A4 -  297 mm x 210 mm 

Right, let's get down to writing some more code.
The dialogue box we have designed will return 3 values :

TYP - Type of Sheet (eg. EL for Electrical)
SIZ - Size of Sheet (eg. A3 for A3 size sheet)
#DWGSC - Drawing Scale (eg. 25 for 1 in 25)

We can now use these values to set up our drawing sheet.
Have a look at the following coding : 

(defun C:SETUP3 ()				;define function
     (setvar "BLIPMODE" 0)			;switch off variables
     (setvar "CMDECHO" 0)
     (setvar "OSMODE" 0)
     (setq typ "e")				;set default
     (setq dcl_id (load_dialog "setup3.dcl"))	;load dialogue
     (if (not 					;test if loaded
           (new_dialog "setup3" 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
     (setq SIZ "A0")				;*Default sheet size
     (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

(if userclick					;*if flag is true
    (progn					;*do the following
           (if (eq siz "A0")			;*If size is A0
             (progn				;*Do the following
		(setq x 1189.0			;*Set x limits
                      y 841.0			;*Set y limits
                )				;*End setq
             )					;*End progn
            )  					;*End If
           (if (eq siz "A1")			;*If size is A1
             (progn				;*Do the following
		(setq x 841.0			;*Set x limits
                      y 594.0			;*Set y limits
                )				;*End setq
             )					;*End progn
            )  					;*End If
           (if (eq siz "A2")			;*If size is A2
             (progn				;*Do the following
		(setq x 594.0			;*Set x limits
                      y 420.0			;*Set y limits
                )				;*End setq
             )					;*End progn
            )  					;*End If
           (if (eq siz "A3")			;*If size is A3
             (progn				;*Do the following
		(setq x 420.0			;*Set x limits
                      y 297.0			;*Set y limits
                )				;*End setq
             )					;*End progn
            )  					;*End If
           (if (eq siz "A4")			;*If size is A4
             (progn				;*Do the following
		(setq x 297.0			;*Set x limits
                      y 210.0			;*Set y limits
                )				;*End setq
             )					;*End progn
            )  					;*End If

           (setq SIZE (strcat TYP SIZ))		;*Construct name of Template 

           (if (eq typ "e") (eng))		;*Run Engineering Setup
           (if (eq typ "a") (arch))		;*Run Architectural Setup
           (if (eq typ "c") (civil))		;*Run Civil Setup
           (if (eq typ "el") (elec))		;*Run Electrical Setup
           (if (eq typ "b") (blank))		;*Run Blank Setup
       
    )						;*End progn
  )						;*End If

 (princ)					;finish clean
)						;end function
;;;----------------------------------------------------------------------------
(defun blank ()					;*Define function

      (setvar "DIMSCALE" #DWGSC)		;*Set Dimscale
      (setvar "USERR1" #DWGSC)			;*Store Scale for future
      (setvar "LTSCALE" (* #DWGSC 10))		;*Set Ltscale
      (setvar "REGENMODE" 1)			;*Regen ON
      (setvar "TILEMODE" 1)			;*Tilemode ON
      (setq n (* 3.5 #DWGSC))			;*Store Text Height

      (setq L (list (* X #DWGSC) (* Y #DWGSC))	;*Calculate Limits
      )

      (command "LIMITS" "0,0" L 
               "ZOOM" "W" "0,0" L
	       "STYLE" "italict"
               "italict" N "" "" "" "" ""
               "INSERT" SIZE "0,0" #DWGSC "" ""
      )						;*Set Up Drawing
       (prompt "\n ")				;*Blank Line
      (prompt "\nO.K Setup Routine Complete")	;*Inform User

 (princ)					;*Exit Quietly
)						;*End Function
;;;----------------------------------------------------------------------------
(princ)						;*Clean Loading
;;;-----------------------------------------------------------------------------

First of all, we check that the O.K. button has been selected.
If the user Cancels, nothing happens and we quietly exit the routine.

If O.K. has been selected, we first check the size of sheet chosen then, set our x and y limits depending on what size sheet was chosen.
Next, we take the type and size of sheet and string them together.
This gives us the name of the Template Drawing that we need to insert.
Clever, Hey....

Following this, we test to see what type of sheet was chosen.
Depending on the type, we run a sub-routine to set up our drawing.

I have deliberate allowed different setup routines for each type of drawing. This makes the program fully customisable and flexible.
Please note that these setup routines are set to my standards and may not suit the way you want to setup a drawing.

Did you notice how I stored the scale factor into USERR1?
This allows you to retrieve the scale factor for later use.
(The value in USERR1 is saved with the drawing.)

On the next page I will list the complete coding for all Sheet Types.

Page I. Home. Page III.
 
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