;;;;; SPACE.LSP v2.0 9/23/99 ;;;;; Copyright (c) 1993, 1999 by J. Marsden DeLapp ;;;;; All rights reserved. ;;;;; ;;;;; A program to space items in a room by picking corners ;;;;; of the room and entering either the maximum spacing or the ;;;;; number of rows and columns. ;;;;; ;;;;; Disclaimer/Agreement ;;;;; Users of Space.lsp must accept this disclaimer of warranty. ;;;;; Space.lsp is provided "as is", with no warranties, express or implied. ;;;;; The author shall not be held liable for any damages resulting from the ;;;;; use of Space.lsp including, without limitation, loss of business ;;;;; profits, interruption of business, loss of information, damage to ;;;;; equipment, or any other incidental or consequential damages. ; ; V2.0 9/23/99 Added Space function to space items by entering rows and columns instead ; of maximum spacing. ; V2.01 11/27/99 Minor bug fix. If ;;;;; (defun C:SPACE (/ ss1 bpt pt1 pt2 pt3 x1 x2 y1 y2 spmax nx ny spx spy) (prompt "\nSelect entity(s) for the array: ") (setq ss1 (ssget) bpt (getpoint "\nEnter base point for entity(s): ") pt1 (getpoint "\nPick a corner of the room: ") pt2 (getcorner pt1 "\nPick opposite corner: ") x1 (car pt1) x2 (car pt2) y1 (cadr pt1) y2 (cadr pt2) spmax (getdist "\nEnter maximum spacing : ") );setq ;;; Make sure that x2 is > x1 and y2 > y1 and swap them if not. (if (> x1 x2) (progn (setq spx x2) ;uses spx as a temp variable (setq x2 x1) (setq x1 spx) );else );endif (if (> y1 y2) (progn (setq spy y2) ;uses spy as a temp variable (setq y2 y1) (setq y1 spy) );else );endif (if (or (not spmax) (= spmax 0.)) (progn (setq ny (getint "\nEnter number of rows: ")) (setq nx (getint "\nEnter number of columns: ")) (setq spmax nil) ) (progn ;;; calculate the number of columns. Be sure to return an int (fix). (setq nx (fix (/ (- x2 x1) spmax))) ;;; if remainder is not 0 then bump up. (Round the number up) (if (/= (rem (- x2 x1) spmax) 0.0) (setq nx (1+ nx)) ) (setq ny (fix (/ (- y2 y1) spmax))) (if (/= (rem (- y2 y1) spmax) 0.0) (setq ny (1+ ny)) ) );progn );endif ;;; Calculate the x and y spacing. (setq spx (/ (- x2 x1) nx)) (setq spy (/ (- y2 y1) ny)) ;;; Setup the insertion point for the block. (setq pt3 (list (+ x1 (/ spx 2)) (+ y1 (/ spy 2)))) (command ".move" ss1 "" bpt pt3) ;;; Choose the correct array command for the number of items to array ;;; Don't array if there is nothing to do. (if (/= nx 1) (if (/= ny 1) (command ".array" ss1 "" "R" ny nx spy spx) ;array both x and y ;else (command ".array" ss1 "" "R" ny nx spx) ;array only x,ny=1 ) (if (/= ny 1) (command ".array" ss1 "" "R" ny nx spy) ;array only y,nx=1 ) ) (if spmax (progn (princ "\nMaximum x or y spacing =") (princ spmax))) (princ "\nActual spacing: x=") (princ spx) (if spmax (progn (princ " (") (princ (* 100 (/ spx spmax))) (princ "%)"))) (princ ", y=") (princ spy) (if spmax (progn (princ " (") (princ (* 100 (/ spy spmax))) (princ "%)"))) (princ) ) (princ "\nSpace.lsp V2.0 Copyright (c) 1993, 1999 by J. Marsden DeLapp ") (princ "\nAll rights reserved. ") (princ)