;*********** MULLION.LSP ********** ; ; Copyright (C) Erik Murray, 1997 ; last modified 2/25/98 ; NOTES ; 2/25/98 - started adding the pieces for a trim rough opening option. Right now it isn't trimming right for polylines. ; I added a double loop in the trim routine to handle polyline rough openings and a check to set the prec ; variable. need to add a toggle box in the dialog for the choice, then get trim to work and enable. ;command names (defun c:MULLION () (mullion) ) (defun c:MUL() (mullion) ) ; Function notes ; -- MULLION displays the dialog box and gathers user input. ; User input includes the rough opening definition, the mullion ; size (both vertical and horizontal) and the number of equal ; spaced panes (both vertical and horizontal). ; -- DRAW_MUL takes the user input and calculates the pane sizes. ; It then draws the mullions and trims their intersections. ; -- this function requires that MULLION.DCL be in the autocad path. ; -- Variables ; dcl_file = the path and name for the dialog box file ; vert_space= number of equal spaced panes in the vertical (global) ; horz_space= number of equal spaced panes in the horizontal (global) ; vert_mul = dimension of the vertical mullions (global) ; horz_mul = dimension of the horizontal mullions (global) ; choice = stores the action number from the dialog box ; pt1 = first point defining the rough opening rectangle ; pt2 = other point defining the rough opening rectangle ; x1 = the translated lower left x coord of rough opening ; x2 = the translated upper right x coord of rough opening ; y1 = the translated lower left y coord of rough opening ; y2 = the translater upper right y coord of rough opening ; eqx = the size of the panes in the horizontal ; eqy = the size of the panes in the vertical ; ctrx = the horizontal loop counter ; ctry = the vertical loop counter ; prec = the required units precision for trimming ; main program (defun mullion (/ dcl_file choice pt1 pt2 old_osmode) ; --error handling-- (defun my_error (s) (if (not (member s '("Function cancelled" "console break"))) (princ (strcat "\nFunction error: " s)) ) (lisp_unsetups) ) ; --begin clean-- (defun lisp_setups () (if (or (wcmatch (getvar "ACADVER") "13*") (wcmatch (getvar "ACADVER") "14*")) (command "_.undo" "_begin") (command "_.undo" "_group") ) ; end if (setq sysvars (mapcar '(lambda (a b) (setq var (getvar a)) (setvar a b) (list a var)) '("cmdecho" "highlight" "lunits" "luprec" "blipmode") '(0 0 4 8 0) ) ) (setq old_error *error* *error* my_error) ) ; --finish clean-- (defun lisp_unsetups() (if sysvars (foreach var sysvars (apply 'setvar var) ) ) (if old_error (setq *error* old_error) ) (command "_.undo" "_end") (setq my_error nil old_error nil sysvars nil) ) ; --get rough opening-- (defun rough_opening () (setvar "OSMODE" OLD_OSMODE) (setq pt1 (getpoint "\nSelect first corner of rough opening...") pt2 (getcorner pt1 "\nSelect other corner of the rough opening...") ) ;end setq (setvar "OSMODE" 0) ) ;end defun rough_opening ; --drawing engine-- (defun draw_mul (pt1 pt2 horz_space vert_space horz_mul vert_mul trim / x1 x2 y1 y2 eqx eqy ctrx ctry prec) (if (= trim 1) (setq prec -0.00390625) (setq prec 0.00390625) ) ;end if ; test for null answers (if (= nil vert_space) (setq vert_space 2)) (if (= nil horz_space) (setq horz_space 2)) (if (= nil vert_mul) (setq vert_mul 1)) (if (= nil horz_mul) (setq horz_mul 1)) (if (or (= nil pt1) (= nil pt2)) ;test (progn ; (alert "Please specify a rough opening now.") (princ "\nPlease specify a rough opening now.") (rough_opening) ) ;then ) ;end if ; calculate mullion spacing (if (> (car pt1) (car pt2)) ;cond (setq x1 (car pt2) x2 (car pt1)) ;then (setq x1 (car pt1) x2 (car pt2)) ;else ) ;end if (if (> (cadr pt1) (cadr pt2)) ;cond (setq y1 (cadr pt2) y2 (cadr pt1)) ;then (setq y1 (cadr pt1) y2 (cadr pt2)) ;else ) ;end if (setq eqx (/ (- (- x2 x1) (* (- horz_space 1) horz_mul)) horz_space)) (setq eqy (/ (- (- y2 y1) (* (- vert_space 1) vert_mul)) vert_space)) ; draw lines (setq ctrx 1) (setq ctry 1) (while (< ctrx horz_space) (command "_.line" (list (+ x1 (* ctrx eqx) (* (- ctrx 1) horz_mul)) y1) (list (+ x1 (* ctrx eqx) (* (- ctrx 1) horz_mul)) y2) "") (command "_.line" (list (+ x1 (* ctrx eqx) (* (- ctrx 1) horz_mul) horz_mul) y1) (list (+ x1 (* ctrx eqx) (* (- ctrx 1) horz_mul) horz_mul) y2) "") (setq ctrx (+ ctrx 1)) ) ;end while (while (< ctry vert_space) (command "_.line" (list x1 (+ y1 (* ctry eqy) (* (- ctry 1) vert_mul))) (list x2 (+ y1 (* ctry eqy) (* (- ctry 1) vert_mul))) "") (command "_.line" (list x1 (+ y1 (* ctry eqy) (* (- ctry 1) vert_mul) vert_mul)) (list x2 (+ y1 (* ctry eqy) (* (- ctry 1) vert_mul) vert_mul)) "") (setq ctry (+ ctry 1)) ) ;end while ; trim mullion intersections (setq eqx (/ (- x2 x1) horz_space)) (setq eqy (/ (- y2 y1) vert_space)) (setq ctrx 1) (setq ctry 1) (princ "\n") (repeat 2 (while (< ctrx horz_space) (princ (strcat "\rTrimming mullion " (itoa ctrx) " of " (itoa (+ horz_space vert_space)) " ")) (command "_.trim" "c" (list (+ x1 prec) (+ y1 prec)) (list (- x2 prec) (- y2 prec)) "" "_f" (list (+ x1 (* ctrx eqx)) (+ y1 prec)) (list (+ (+ x1 prec) (* ctrx eqx)) (- y2 prec)) "" "") (setq ctrx (+ ctrx 1)) ) ;end while ) ;end repeat (repeat 2 (while (< ctry vert_space) (princ (strcat "\rTrimming mullion " (itoa (+ ctrx ctry)) " of " (itoa (+ horz_space vert_space)) " ")) (command "_.trim" "c" (list (+ x1 prec) (+ y1 prec)) (list (- x2 prec) (- y2 prec)) "" "_f" (list (+ x1 prec) (+ y1 (* ctry eqy))) (list (- x2 prec) (+ y1 (* ctry eqy))) "" "") (setq ctry (+ ctry 1)) ) ;end while ) ;end repeat (princ "\rTrimming mullions ... done! ") ) ;end draw_mul ; -- main program -- (lisp_setups) (setq choice 2 old_osmode (getvar "OSMODE") ) (if (not trim) (setq trim 0)) (setvar "OSMODE" 0) (if (= nil vert_space) (setq vert_space 2)) (if (= nil horz_space) (setq horz_space 2)) (if (= nil vert_mul) (setq vert_mul 1)) (if (= nil horz_mul) (setq horz_mul 1)) (if (= 0 (getvar "tilemode")) ;test 1 (alert "MULLION cannot be used in paperspace.") ;then 1 (progn (if (setq dcl_file (load_dialog "MULLION.DCL")) ;test 2 (while (< 1 choice) (if (new_dialog "main" dcl_file) ;test 3 (progn (set_tile "vert_space" (itoa vert_space)) (set_tile "horz_space" (itoa horz_space)) (set_tile "vert_mul" (rtos vert_mul)) (set_tile "horz_mul" (rtos horz_mul)) (set_tile "trim" (itoa trim)) (action_tile "rough_opng" "(done_dialog 2)") (action_tile "vert_space" "(setq vert_space (atoi $value))") (action_tile "horz_space" "(setq horz_space (atoi $value))") (action_tile "vert_mul" "(setq vert_mul (atof $value))") (action_tile "horz_mul" "(setq horz_mul (atof $value))") (action_tile "trim" "(setq trim (atoi $value))") (action_tile "accept" "(done_dialog 1)") (action_tile "cancel" "(done_dialog 0)") (setq choice (start_dialog)) (cond ((= choice 2) (rough_opening)) ((= choice 1) (draw_mul pt1 pt2 horz_space vert_space horz_mul vert_mul trim)) ((= choice 0) (princ "\nFunction cancelled.")) (t nil) ) ;end cond ) ;end progn and then 3 (alert "Could not find dialog definition: MULLION") ;else 3 ) ;end if 3 ) ;end while and then 2 (alert "Could not find file: MULLION.DCL") ;else 2 ) (unload_dialog dcl_file) ) ;end if 2 and else 1 ) ;end if 1 (setvar "OSMODE" OLD_OSMODE) (lisp_unsetups) (princ) )