;Version: 121.4d ;Date : 29 December 1999 ; ;This program now handles two dimensional lay out. ;Okay, before I forget I'll quickly explain what goes on in this edition. ;I finished off last time with 121.3 (or 121z.lsp) which could ;automatically detect lying and standing rectangular rooms and place ;one and only one row of desirable number of lights across the middle. ;121.4 can now position numerous number of rows in a 2-D manner if you like ;to see this as. ; ;Mechanism: I took 121.3 and removed its Lying part, keeping the Standing ;part. This program breaks up the big room into many small standing rectangular ;rooms and then feeds appropriate coordinates into the old standing(). ;Everything is basically the same as before, except we've now added the ;outerloop and removed the lying part. ; ;Bug Fix: In previous versions, the background always seemed to interfere ;with our positioning for some unknown reason. I figured out it ;must be due to osnap. That problem has been fixed in this version. ; ;Future development: I think one purpose of LSP is to minimize the number of ;questions the user needs to answer. 121.4 already asks 5 questions, ;and I am reluctant to make it worse. However if I do come back and improve ;on this edition, I look forward to including (1) a rotation function ;and (2) default/memory for previous corners (3) automatically calculate from ;the dimensions how many lights to place and how to place them and then place ;them automatically (4) Rather than needing to select two opposite corner points ;of the room, I hope to let the user click any where inside the room once and ;only once, and leave it to the program to detect the corners and dimensions. (defun c:121() (setq p1 (getpoint "\n1st corner:")) (setq p3 (getpoint "\n2nd corner (furthest opposite):")) ;set default for r to light.dwg (if (= r nil) (setq r "light.dwg")) ;default or memory recall (princ "\nWhat block <") (princ r) (princ ">?") (setq s (getstring " ")) ;this renews previous setting ;provides default and memory function (setq r0 r) (if (/= r s) (setq r s)) (if (= s "") (setq r r0)) ;n is number of lights to fit into each vertical row (setq n (getint "\nHow many in each vertical row? ")) ;m is number of lights to fit into each horizontal row (setq m (getint "\nHow many in each horizontal row? ")) (setq x1 (car p1)) (setq y1 (cadr p1)) (setq x9 (car p3)) (setq y3 (cadr p3)) ;It is important that we clear the osnap before we start inserting blocks ;because any ON osnap attribute can interact with the background structures ;and stuff up our coordinates. ;Memorizing osnap status into the variable ostatus before we clear osnap (setq ostatus (getvar "osmode") ) ;Clearing osnap (setvar "osmode" 0) ;START OF OUTER LOOP ;dd is the absolute width of the corridor (setq dd (- x9 x1)) ;tt is the distance of first light from wall, ie. unit distance. ;2m comes from 2(m-1)+2 (setq tt (/ dd (* 2 m))) ;qq1 represents the absolute x value of lights in specific vertical row ;We in effect, wish to feed qq1-tt and qq1+tt into standing() for it to ;complete the content of each vertical row for us ;Here we go, this is the x value for lights in the first vertical row (setq qq1 (+ x1 tt)) ;for a=0 to m (setq a 0) (setq b 1) (while b (setq x1 (- qq1 tt)) (setq x3 (+ qq1 tt)) (standing) (setq qq1 (+ qq1 (* tt 2) ) ) (setq a (+ a 1)) (if (= a m) (setq b nil)) ) ;next a ; END OF OUTER LOOP ;Returning initial osnap settings (setvar "osmode" ostatus) ;get rid of end nil (princ) ) ;main program ends here ; START OF INNER LOOP ;start of function standing (defun standing() (setq xmid (/ (+ x1 x3) 2)) ;d is the height of the corridor (setq d (- y3 y1)) ;t is the distance of first light from wall, ie. unit distance. ;2n comes from 2(n-1)+2 (setq t (/ d (* 2 n))) ;q1 is an arbitary point in the corridor with xmid as its x value (setq q1 (+ y1 t)) ;for j=0 to n-2 (setq j 0) (setq w 1) (while w (setq q (+ q1 (* (* 2 t) j))) (setq j (+ j 1)) (if (= j n) (setq w nil)) (setq z (list xmid q)) (command "insert" r z "" "" "") ) ;next j ) ; END OF INNER LOOP