; The Codewriting Workbook ; Creating Computational Architecture in AutoLISP ; by Robert J. Krawczyk ; Princeton Architectural Press, 2008 ; -------------------------------------------------------------------------- ; CH06E.LSP ; -------------------------------------------------------------------------- ; Disclaimer: The information contained in this file is distributed on an ; "as is" basis, without warranty. Although every precaution has been taken ; in the preparation of this work, the author and publisher shall not have ; any liability to any person or entity with respect to any loss or damage ; caused or alleged to be caused directly or indirectly by the information ; contained in this work. ; -------------------------------------------------------------------------- (defun dtr (a) (* pi (/ a 180.0))) (defun rtd (a) (/ (* a 180.0) pi)) ; -------------------------------------------------------------------------- (defun sign (a) (if (< a 0.0) (- 0 1.0) (+ 0 1.0))) ; -------------------------------------------------------------------------- (defun rn (/ modulus multiplier increment random) (if (not rnseed) (setq rnseed (getvar "DATE"))) (setq modulus 65536 multiplier 25173 increment 13849 rnseed (rem (+ (* multiplier seed) increment) modulus) random (/ rnseed modulus) ) ) ;--------------------------------------------------------------------------- ; -------------------------------------------------------------------------- (defun rotate2d ( pt ptc ang / pt1 pt2 ) ; rotate pt ang degrees (setq pt1 (list (+ (nth 0 pt) (- 0 (nth 0 ptc))) (+ (nth 1 pt) (- 0 (nth 1 ptc))) (nth 2 pt))) (setq pt2 (list (- (* (nth 0 pt1) (cos (dtr ang))) (* (nth 1 pt1) (sin (dtr ang)))) (+ (* (nth 0 pt1) (sin (dtr ang))) (* (nth 1 pt1) (cos (dtr ang)))) (nth 2 pt))) (list (+ (nth 0 pt2) (+ 0 (nth 0 ptc))) (+ (nth 1 pt2) (+ 0 (nth 1 ptc))) (nth 2 pt)) ) ;--------------------------------------------------------------------------- ;--------------------------------------------------------------------------- ; ZW - zoom window (defun c:zw () (command "zoom" "w") ) ; ZP - zoom previous (defun c:zp () (command "zoom" "p") ) ; ZE - zoom extents (defun c:ze () (command "zoom" "e" "zoom" ".9x") ) ; ZX - zoom .9x (defun c:zx () (command "zoom" ".9x") ) ;--------------------------------------------------------------------------- ; VT - top view (defun c:vt () (command "vpoint" "r" 270 90) (command "zoom" "e" "ucs" "v" "zoom" ".9x") (princ) ) ; VL - left view (defun c:vl () (command "vpoint" "r" 180 0) (command "zoom" "e" "ucs" "v" "zoom" ".9x") (princ) ) ; VR - right view (defun c:vr () (command "vpoint" "r" 0 0) (command "zoom" "e" "ucs" "v" "zoom" ".9x") (princ) ) ; VF - front view (defun c:vf () (command "vpoint" "r" 270 0) (command "zoom" "e" "ucs" "v" "zoom" ".9x") (princ) ) ; VB - back view (defun c:vb () (command "vpoint" "r" 90 0) (command "zoom" "e" "ucs" "v" "zoom" ".9x") (princ) ) ; VSW - SW view (defun c:vsw () (command "vpoint" "r" 270 90) (command "ucs" "v") (command "vpoint" "r" 225 45) (command "zoom" "e" "zoom" ".9x") (princ) ) ; VSE - SE view (defun c:vse () (command "vpoint" "r" 270 90) (command "ucs" "v") (command "vpoint" "r" 315 45) (command "zoom" "e" "zoom" ".9x") (princ) ) ; VNE - NE view (defun c:vne () (command "vpoint" "r" 270 90) (command "ucs" "v") (command "vpoint" "r" 45 45) (command "zoom" "e" "zoom" ".9x") (princ) ) ;-------------------------------------------------------------------------- ;-------------------------------------------------------------------------- ;-------------------------------------------------------------------------- (defun prog01 () (graphscr) (command ".ERASE" "all" "") ; set start point (setq pnt0 (list 0 0 0)) (setq xyside (getdist pnt0 "\nEnter XY side:")) (setq xtimes (getint "\nEnter number X repeats:")) (setq ytimes (getint "\nEnter number Y repeats:")) (setq zheight (getdist "\Enter Z height: ")) (setq nlevels (getint "\Enter number of levels: ")) (setq angz (getreal "\Enter angle multiple: ")) ; start Z location (setq zelev 0.0) (repeat nlevels ; level block (setq pnt1 (list (+ (nth 0 pnt0) (/ xyside 2.0)) (+ (nth 1 pnt0) (/ xyside 2.0)) zelev)) (setq pnt2 (list (+ (nth 0 pnt1) (- (* xtimes xyside) xyside)) (+ (nth 1 pnt1) (- (* ytimes xyside) xyside)) zelev)) (command ".RECTANGLE" pnt1 pnt2) (command ".ZOOM" "e") (command ".EXTRUDE" "last" "" zheight) ; versions prior to 2007 require the taper parameter ;(command ".EXTRUDE" "last" "" zheight "") ; add to level list (setq llist (ssadd (entlast))) ; start y location (setq ynum 1) (setq yloc (nth 1 pnt0)) (repeat ytimes ; start x location (setq xnum 1) (setq xloc (nth 0 pnt0)) (repeat xtimes ; only if at edge (if (or (= ynum 1) (= ynum ytimes) (= xnum 1) (= xnum xtimes)) (progn ; lower corner pt (setq pnt1 (list xloc yloc zelev)) ; center of grid (setq pnt2 (list (+ (nth 0 pnt1) (/ xyside 2)) (+ (nth 1 pnt1) (/ xyside 2)) zelev)) ; rotate ang (setq rotang (* (fix (* (rn) 10.0)) angz)) ; draw rectangle (command ".POLYGON" "4" pnt2 "I" (/ xyside 2.0)) (command ".ZOOM" "e") (command ".ROTATE" "last" "" pnt2 rotang) ; extrude to height (command ".EXTRUDE" "last" "" zheight) ; versions prior to 2007 require the taper parameter ;(command ".EXTRUDE" "last" "" zheight "") ; add to selection list (setq llist (ssadd (entlast) llist)) )) ; inc x location (setq xloc (+ xloc xyside)) (setq xnum (+ xnum 1)) ) ; inc y location (setq yloc (+ yloc xyside)) (setq ynum (+ ynum 1)) ) ; union level (command ".UNION" llist "") ; inc levels elev (setq zelev (+ zelev zheight)) ) (princ) ) ;-------------------------------------------------------------------------- (defun prog01a () (graphscr) (command ".ERASE" "all" "") ; set start point (setq pnt0 (list 0 0 0)) (setq xyside (getdist pnt0 "\nEnter XY side:")) (setq xtimes (getint "\nEnter number X repeats:")) (setq ytimes (getint "\nEnter number Y repeats:")) (setq zheight (getdist "\Enter Z height: ")) (setq nlevels (getint "\Enter number of levels: ")) (setq angz (getreal "\Enter angle multiple: ")) ; start Z location (setq zelev 0.0) (repeat nlevels ; level block (setq pnt1 (list (+ (nth 0 pnt0) (/ xyside 2.0)) (+ (nth 1 pnt0) (/ xyside 2.0)) zelev)) (setq pnt2 (list (+ (nth 0 pnt1) (- (* xtimes xyside) xyside)) (+ (nth 1 pnt1) (- (* ytimes xyside) xyside)) zelev)) (command ".RECTANGLE" pnt1 pnt2) (command ".ZOOM" "e") (command ".EXTRUDE" "last" "" zheight) ; versions prior to 2007 require the taper parameter ;(command ".EXTRUDE" "last" "" zheight "") ; add to level list (setq llist (ssadd (entlast))) ; start y location (setq ynum 1) (setq yloc 0) (repeat ytimes ; start x location (setq xnum 1) (setq xloc 0) (repeat xtimes ; only if at edge (if (or (or (or (= ynum 1) (= ynum ytimes)) (= xnum 1)) (= xnum xtimes)) (progn ; lower corner pt (setq pnt1 (list xloc yloc zelev)) ; center of grid (setq pnt2 (list (+ (nth 0 pnt1) (/ xyside 2)) (+ (nth 1 pnt1) (/ xyside 2)) zelev)) ; flag to draw (setq ido 1) ; rotate ang (setq rotang (* (fix (* (rn) 10.0)) angz)) ; check rotation (if (= (rem rotang 90) 0) (setq ido 0)) ; check for corners (if (and (= ynum 1) (= xnum 1)) (setq ido 0)) (if (and (= ynum 1) (= xnum xtimes)) (setq ido 0)) (if (and (= xnum 1) (= ynum ytimes)) (setq ido 0)) (if (and (= xnum xtimes) (= ynum ytimes)) (setq ido 0)) ; check flag (if (= ido 1) (progn ; draw rectangle (command ".POLYGON" "4" pnt2 "I" (/ xyside 2.0)) (command ".ZOOM" "e") (command ".ROTATE" "last" "" pnt2 rotang) ; extrude to height (command ".EXTRUDE" "last" "" zheight) ; versions prior to 2007 require the taper parameter ;(command ".EXTRUDE" "last" "" zheight "") ; add to selection list (setq llist (ssadd (entlast) llist)) )) )) ; inc x location (setq xloc (+ xloc xyside)) (setq xnum (+ xnum 1)) ) ; inc y location (setq yloc (+ yloc xyside)) (setq ynum (+ ynum 1)) ) ; union level (command ".UNION" llist "") ; inc levels elev (setq zelev (+ zelev zheight)) ) (princ) ) ;-------------------------------------------------------------------------- (defun prog01b () (graphscr) (command ".ERASE" "all" "") ; set start point (setq pnt0 (list 0 0 0)) (setq xyside (getdist pnt0 "\nEnter XY side:")) (setq xtimes (getint "\nEnter number X repeats:")) (setq ytimes (getint "\nEnter number Y repeats:")) (setq zheight (getdist "\Enter Z height: ")) (setq zthk (getdist "\Enter slab thickness: ")) (setq nlevels (getint "\Enter number of levels: ")) (setq angz (getreal "\Enter angle multiple: ")) ; start Z location (setq zelev 0.0) (repeat nlevels ; level block (setq pnt1 (list (+ (nth 0 pnt0) (/ xyside 2.0)) (+ (nth 1 pnt0) (/ xyside 2.0)) zelev)) (setq pnt2 (list (+ (nth 0 pnt1) (- (* xtimes xyside) xyside)) (+ (nth 1 pnt1) (- (* ytimes xyside) xyside)) zelev)) (command ".RECTANGLE" pnt1 pnt2) (command ".ZOOM" "e") (command ".EXTRUDE" "last" "" zheight) ; versions prior to 2007 require the taper parameter ;(command ".EXTRUDE" "last" "" zheight "") ; add to level list (setq llist (ssadd (entlast))) ; add slab (setq pnt1 (list (nth 0 pnt0) (nth 1 pnt0) zelev)) (setq pnt2 (list (+ (nth 0 pnt1) (* xtimes xyside)) (+ (nth 1 pnt1) (* ytimes xyside)) zelev)) (command ".RECTANGLE" pnt1 pnt2) (command ".EXTRUDE" "last" "" zthk) ; versions prior to 2007 require the taper parameter ;(command ".EXTRUDE" "last" "" zheight "") ; add to level list (setq llist (ssadd (entlast) llist)) ; start y location (setq ynum 1) (setq yloc 0) (repeat ytimes ; start x location (setq xnum 1) (setq xloc 0) (repeat xtimes ; only if at edge (if (or (or (or (= ynum 1) (= ynum ytimes)) (= xnum 1)) (= xnum xtimes)) (progn ; lower corner pt (setq pnt1 (list xloc yloc zelev)) ; center of grid (setq pnt2 (list (+ (nth 0 pnt1) (/ xyside 2)) (+ (nth 1 pnt1) (/ xyside 2)) zelev)) ; flag to draw (setq ido 1) ; rotate ang (setq rotang (* (fix (* (rn) 10.0)) angz)) ; check rotation (if (= (rem rotang 90) 0) (setq ido 0)) ; check for corners (if (and (= ynum 1) (= xnum 1)) (setq ido 0)) (if (and (= ynum 1) (= xnum xtimes)) (setq ido 0)) (if (and (= xnum 1) (= ynum ytimes)) (setq ido 0)) (if (and (= xnum xtimes) (= ynum ytimes)) (setq ido 0)) ; check flag (if (= ido 1) (progn ; draw rectangle (command ".POLYGON" "4" pnt2 "I" (/ xyside 2.0)) (command ".ZOOM" "e") (command ".ROTATE" "last" "" pnt2 rotang) ; extrude to height (command ".EXTRUDE" "last" "" zheight) ; versions prior to 2007 require the taper parameter ;(command ".EXTRUDE" "last" "" zheight "") ; add to selection list (setq llist (ssadd (entlast) llist)) )) )) ; inc x location (setq xloc (+ xloc xyside)) (setq xnum (+ xnum 1)) ) ; inc y location (setq yloc (+ yloc xyside)) (setq ynum (+ ynum 1)) ) ; union level (command ".UNION" llist "") ; inc levels elev (setq zelev (+ zelev zheight)) ) (princ) ) ;-------------------------------------------------------------------------- ;-------------------------------------------------------------------------- (defun prog02 () (graphscr) (command ".ERASE" "all" "") ; set start point (setq pnt0 (list 0 0 0)) (setq xyside (getdist pnt0 "\nEnter XY side:")) (setq xtimes (getint "\nEnter number X repeats:")) (setq ytimes (getint "\nEnter number Y repeats:")) (setq zheight (getdist "\Enter Z height: ")) (setq nlevels (getint "\Enter number of levels: ")) (setq psides (getint "\Enter polygon sides: ")) (setq prad (getdist "\Enter polygon radius: ")) (setq angz (getreal "\Enter angle multiple: ")) (setq angzx (getreal "\Enter angle multiple to exclude: ")) ; start Z location (setq zelev 0.0) (repeat nlevels ; level block (setq pnt1 (list (+ (nth 0 pnt0) (/ xyside 2.0)) (+ (nth 1 pnt0) (/ xyside 2.0)) zelev)) (setq pnt2 (list (+ (nth 0 pnt1) (- (* xtimes xyside) xyside)) (+ (nth 1 pnt1) (- (* ytimes xyside) xyside)) zelev)) (command ".RECTANGLE" pnt1 pnt2) (command ".ZOOM" "e") (command ".EXTRUDE" "last" "" zheight) ; versions prior to 2007 require the taper parameter ;(command ".EXTRUDE" "last" "" zheight "") ; add to level list (setq llist (ssadd (entlast))) ; start y location (setq ynum 1) (setq yloc 0) (repeat ytimes ; start x location (setq xnum 1) (setq xloc 0) (repeat xtimes ; only if at edge (if (or (or (or (= ynum 1) (= ynum ytimes)) (= xnum 1)) (= xnum xtimes)) (progn ; lower corner pt (setq pnt1 (list xloc yloc zelev)) ; center of grid (setq pnt2 (list (+ (nth 0 pnt1) (/ xyside 2)) (+ (nth 1 pnt1) (/ xyside 2)) zelev)) ; flag to draw (setq ido 1) ; rotate ang (setq rotang (* (fix (* (rn) 10.0)) angz)) ; check rotation (if (= (rem rotang angzx) 0) (setq ido 0)) ; check for corners (if (and (= ynum 1) (= xnum 1)) (setq ido 0)) (if (and (= ynum 1) (= xnum xtimes)) (setq ido 0)) (if (and (= xnum 1) (= ynum ytimes)) (setq ido 0)) (if (and (= xnum xtimes) (= ynum ytimes)) (setq ido 0)) ; check flag (if (= ido 1) (progn ; draw rectangle (command ".POLYGON" psides pnt2 "I" prad) (command ".ZOOM" "e") (command ".ROTATE" "last" "" pnt2 rotang) ; extrude to height (command ".EXTRUDE" "last" "" zheight) ; versions prior to 2007 require the taper parameter ;(command ".EXTRUDE" "last" "" zheight "") ; add to selection list (setq llist (ssadd (entlast) llist)) )) )) ; inc x location (setq xloc (+ xloc xyside)) (setq xnum (+ xnum 1)) ) ; inc y location (setq yloc (+ yloc xyside)) (setq ynum (+ ynum 1)) ) ; union level (command ".UNION" llist "") ; inc levels elev (setq zelev (+ zelev zheight)) ) (princ) ) ;-------------------------------------------------------------------------- ;-------------------------------------------------------------------------- (defun prog03 () (graphscr) (command ".ERASE" "all" "") ; set start point (setq pnt0 (list 0 0 0)) (setq xyside (getdist pnt0 "\nEnter XY side:")) (setq xtimes (getint "\nEnter number X repeats:")) (setq ytimes (getint "\nEnter number Y repeats:")) (setq zheight (getdist "\Enter Z height: ")) (setq nlevels (getint "\Enter number of levels: ")) (setq cradmin (getdist "\Enter circle min radius: ")) (setq cradmax (getdist "\Enter circle max radius: ")) ; start Z location (setq zelev 0.0) (repeat nlevels ; level block (setq pnt1 (list (+ (nth 0 pnt0) (/ xyside 2.0)) (+ (nth 1 pnt0) (/ xyside 2.0)) zelev)) (setq pnt2 (list (+ (nth 0 pnt1) (- (* xtimes xyside) xyside)) (+ (nth 1 pnt1) (- (* ytimes xyside) xyside)) zelev)) (command ".RECTANGLE" pnt1 pnt2) (command ".ZOOM" "e") (command ".EXTRUDE" "last" "" zheight) ; versions prior to 2007 require the taper parameter ;(command ".EXTRUDE" "last" "" zheight "") ; add to level list (setq llist (ssadd (entlast))) ; start y location (setq ynum 1) (setq yloc 0) (repeat ytimes ; start x location (setq xnum 1) (setq xloc 0) (repeat xtimes ; only if at edge (if (or (or (or (= ynum 1) (= ynum ytimes)) (= xnum 1)) (= xnum xtimes)) (progn ; lower corner pt (setq pnt1 (list xloc yloc zelev)) ; center of grid (setq pnt2 (list (+ (nth 0 pnt1) (/ xyside 2)) (+ (nth 1 pnt1) (/ xyside 2)) zelev)) ; comoute radius (setq crad (+ cradmin (* (rn) (- cradmax cradmin)))) ; draw circle (command ".CIRCLE" pnt2 crad) (command ".ZOOM" "e") ; extrude to height (command ".EXTRUDE" "last" "" zheight) ; versions prior to 2007 require the taper parameter ;(command ".EXTRUDE" "last" "" zheight "") ; add to selection list (setq llist (ssadd (entlast) llist)) )) ; inc x location (setq xloc (+ xloc xyside)) (setq xnum (+ xnum 1)) ) ; inc y location (setq yloc (+ yloc xyside)) (setq ynum (+ ynum 1)) ) ; union level (command ".UNION" llist "") ; inc levels elev (setq zelev (+ zelev zheight)) ) (princ) ) ;-------------------------------------------------------------------------- (defun prog03a () (graphscr) (command ".ERASE" "all" "") ; set start point (setq pnt0 (list 0 0 0)) (setq xyside (getdist pnt0 "\nEnter XY side:")) (setq xtimes (getint "\nEnter number X repeats:")) (setq ytimes (getint "\nEnter number Y repeats:")) (setq zheight (getdist "\Enter Z height: ")) (setq nlevels (getint "\Enter number of levels: ")) (setq cradmin (getdist "\Enter circle min radius: ")) (setq cradmax (getdist "\Enter circle max radius: ")) ; start Z location (setq zelev 0.0) (repeat nlevels ; level block (setq pnt1 (list (+ (nth 0 pnt0) (/ xyside 2.0)) (+ (nth 1 pnt0) (/ xyside 2.0)) zelev)) (setq pnt2 (list (+ (nth 0 pnt1) (- (* xtimes xyside) xyside)) (+ (nth 1 pnt1) (- (* ytimes xyside) xyside)) zelev)) (command ".RECTANGLE" pnt1 pnt2) (command ".ZOOM" "e") (command ".EXTRUDE" "last" "" zheight) ; versions prior to 2007 require the taper parameter ;(command ".EXTRUDE" "last" "" zheight "") ; add to level list (setq llist (ssadd (entlast))) ; start y location (setq ynum 1) (setq yloc 0) (repeat ytimes ; start x location (setq xnum 1) (setq xloc 0) (repeat xtimes ; only if at edge (if (or (or (or (= ynum 1) (= ynum ytimes)) (= xnum 1)) (= xnum xtimes)) (progn ; lower corner pt (setq pnt1 (list xloc yloc zelev)) ; center of grid (setq pnt2 (list (+ (nth 0 pnt1) (/ xyside 2)) (+ (nth 1 pnt1) (/ xyside 2)) zelev)) ; comoute radius (setq crad (+ cradmin (* (rn) (- cradmax cradmin)))) ; draw circle (command ".CIRCLE" pnt2 crad) (command ".ZOOM" "e") ; extrude to slab thickness (command ".EXTRUDE" "last" "" zthk) ; versions prior to 2007 require the taper parameter ;(command ".EXTRUDE" "last" "" zthk "") ; add to selection list (setq llist (ssadd (entlast) llist)) )) ; inc x location (setq xloc (+ xloc xyside)) (setq xnum (+ xnum 1)) ) ; inc y location (setq yloc (+ yloc xyside)) (setq ynum (+ ynum 1)) ) ; union level (command ".UNION" llist "") ; inc levels elev (setq zelev (+ zelev zheight)) ) (princ) ) ;-------------------------------------------------------------------------- ;-------------------------------------------------------------------------- (defun prog04 () (graphscr) (command ".ERASE" "all" "") ; set start point (setq pnt0 (list 0 0 0)) (setq xyside (getdist pnt0 "\nEnter XY side:")) (setq xtimes (getint "\nEnter number X repeats:")) (setq ytimes (getint "\nEnter number Y repeats:")) (setq zheight (getdist "\Enter Z height: ")) (setq nlevels (getint "\Enter number of levels: ")) (setq ymaxoff (getdist "\Enter max Y offset: ")) (setq angy (getreal "\Enter angle multiple: ")) (setq ycycles (getreal "\Enter number of curve cycles: ")) ; start Z location (setq zelev 0.0) (repeat nlevels ; start edge (command ".PLINE") ; curve angles (setq xang (* (fix (* (rn) 24)) angy)) (setq xanginc (/ (* 360.0 ycycles) xtimes)) (setq xloc (nth 0 pnt0)) (setq yloc (nth 1 pnt0)) (setq xnum 1) (repeat (+ xtimes 1) ; compute Y offset based on curve (setq yoff (* (sin (dtr xang)) ymaxoff)) (setq npnt (list xloc (+ yloc yoff) zelev)) (command npnt) ; save first pt (if (= xnum 1) (setq fpnt npnt)) ; inc x location and angs (setq xloc (+ xloc xyside)) (setq xang (+ xang xanginc)) (setq xnum (+ xnum 1)) ) ; level corner pts (setq pnt1 (list (+ (nth 0 pnt0) (* xtimes xyside)) (+ (nth 1 pnt0) (* ytimes xyside)) zelev)) (setq pnt2 (list (nth 0 pnt0) (+ (nth 1 pnt0) (* ytimes xyside)) zelev)) (command pnt1 pnt2 fpnt) ; close polyline (command "c") (command ".ZOOM" "e") ; extrude to height (command ".EXTRUDE" "last" "" zheight) ; versions prior to 2007 require the taper parameter ;(command ".EXTRUDE" "last" "" zheight "") ; inc levels elev (setq zelev (+ zelev zheight)) ) (princ) ) ;-------------------------------------------------------------------------- (defun prog04a () (graphscr) (command ".ERASE" "all" "") ; set start point (setq pnt0 (list 0 0 0)) (setq xyside (getdist pnt0 "\nEnter XY side:")) (setq xtimes (getint "\nEnter number X repeats:")) (setq ytimes (getint "\nEnter number Y repeats:")) (setq zheight (getdist "\Enter Z height: ")) (setq nlevels (getint "\Enter number of levels: ")) (setq ymaxoff (getdist "\Enter max Y offset: ")) (setq angy (getreal "\Enter angle multiple: ")) (setq ycycles (getreal "\Enter number of curve cycles: ")) ; start Z location (setq zelev 0.0) (repeat nlevels ; start edge (command ".PLINE") ; curve angles (setq xang (* (fix (* (rn) 24)) angy)) (setq xanginc (/ (* 360.0 (+ (* (rn) ycycles) 0.5)) xtimes)) (setq xloc (nth 0 pnt0)) (setq yloc (nth 1 pnt0)) (setq xnum 1) (repeat (+ xtimes 1) ; compute Y offset based on curve (setq yoff (* (sin (dtr xang)) ymaxoff)) (setq npnt (list xloc (+ yloc yoff) zelev)) (command npnt) ; save first pt (if (= xnum 1) (setq fpnt npnt)) ; inc x location and angs (setq xloc (+ xloc xyside)) (setq xang (+ xang xanginc)) (setq xnum (+ xnum 1)) ) ; level corner pts (setq pnt1 (list (+ (nth 0 pnt0) (* xtimes xyside)) (+ (nth 1 pnt0) (* ytimes xyside)) zelev)) (setq pnt2 (list (nth 0 pnt0) (+ (nth 1 pnt0) (* ytimes xyside)) zelev)) (command pnt1 pnt2 fpnt) ; close polyline (command "c") (command ".ZOOM" "e") ; extrude to height (command ".EXTRUDE" "last" "" zheight) ; versions prior to 2007 require the taper parameter ;(command ".EXTRUDE" "last" "" zheight "") ; inc levels elev (setq zelev (+ zelev zheight)) ) (princ) ) ;-------------------------------------------------------------------------- (defun prog04b () (graphscr) (command ".ERASE" "all" "") ; set start point (setq pnt0 (list 0 0 0)) (setq xyside (getdist pnt0 "\nEnter XY side:")) (setq xtimes (getint "\nEnter number X repeats:")) (setq ytimes (getint "\nEnter number Y repeats:")) (setq zheight (getdist "\Enter Z height: ")) (setq zthk (getdist "\Enter slab thickness: ")) (setq nlevels (getint "\Enter number of levels: ")) (setq ymaxoff (getdist "\Enter max Y offset: ")) (setq angy (getreal "\Enter angle multiple: ")) (setq ycycles (getreal "\Enter number of curve cycles: ")) ; start Z location (setq zelev 0.0) (repeat nlevels ; start edge (command ".PLINE") ; curve angles (setq xang (* (fix (* (rn) 24)) angy)) (setq xanginc (/ (* 360.0 ycycles) xtimes)) (setq xloc (nth 0 pnt0)) (setq yloc (nth 1 pnt0)) (setq xnum 1) (repeat (+ xtimes 1) ; compute Y offset based on curve (setq yoff (* (sin (dtr xang)) ymaxoff)) (setq npnt (list xloc (+ yloc yoff) zelev)) (command npnt) ; save first pt (if (= xnum 1) (setq fpnt npnt)) ; inc x location and angs (setq xloc (+ xloc xyside)) (setq xang (+ xang xanginc)) (setq xnum (+ xnum 1)) ) ; level corner pts (setq pnt1 (list (+ (nth 0 pnt0) (* xtimes xyside)) (+ (nth 1 pnt0) (* ytimes xyside)) zelev)) (setq pnt2 (list (nth 0 pnt0) (+ (nth 1 pnt0) (* ytimes xyside)) zelev)) (command pnt1 pnt2 fpnt) ; close polyline (command "c") (command ".ZOOM" "e") ; extrude to height (command ".EXTRUDE" "last" "" zthk) ; versions prior to 2007 require the taper parameter ;(command ".EXTRUDE" "last" "" zthk "") ; add to list (setq llist (ssadd (entlast))) ; floor mass (setq pnt1 (list (nth 0 pnt0) (+ (nth 1 pnt0) ymaxoff) zelev)) (setq pnt2 (list (+ (nth 0 pnt0) (* xtimes xyside)) (+ (nth 1 pnt0) (* ytimes xyside)) zelev)) (command ".RECTANGLE" pnt1 pnt2) ; extrude to height (command ".EXTRUDE" "last" "" zheight) ; versions prior to 2007 require the taper parameter ;(command ".EXTRUDE" "last" "" zheight "") ; add to list (setq llist (ssadd (entlast) llist)) ; union level (command ".UNION" llist "") ; inc levels elev (setq zelev (+ zelev zheight)) ) (princ) ) ;-------------------------------------------------------------------------- ;-------------------------------------------------------------------------- (defun prog04c () (graphscr) (command ".ERASE" "all" "") ; set start point (setq pnt0 (list 0 0 0)) (setq xyside (getdist pnt0 "\nEnter XY side:")) (setq xtimes (getint "\nEnter number X repeats:")) (setq ytimes (getint "\nEnter number Y repeats:")) (setq zheight (getdist "\Enter Z height: ")) (setq zthk (getdist "\Enter slab thickness: ")) (setq nlevels (getint "\Enter number of levels: ")) (setq ymaxoff (getdist "\Enter max Y offset: ")) (setq angy (getreal "\Enter angle multiple: ")) (setq ycycles (getreal "\Enter number of curve cycles: ")) ; start Z location (setq zelev 0.0) ; starting curve angle (setq sxang (* (fix (* (rn) 24)) angy)) (repeat nlevels ; start edge (command ".PLINE") ; curve angles (setq xang sxang) (setq xanginc (/ (* 360.0 ycycles) xtimes)) (setq xloc (nth 0 pnt0)) (setq yloc (nth 1 pnt0)) (setq xnum 1) (repeat (+ xtimes 1) ; compute Y offset based on curve (setq yoff (* (sin (dtr xang)) ymaxoff)) (setq npnt (list xloc (+ yloc yoff) zelev)) (command npnt) ; save first pt (if (= xnum 1) (setq fpnt npnt)) ; inc x location and angs (setq xloc (+ xloc xyside)) (setq xang (+ xang xanginc)) (setq xnum (+ xnum 1)) ) ; level corner pts (setq pnt1 (list (+ (nth 0 pnt0) (* xtimes xyside)) (+ (nth 1 pnt0) (* ytimes xyside)) zelev)) (setq pnt2 (list (nth 0 pnt0) (+ (nth 1 pnt0) (* ytimes xyside)) zelev)) (command pnt1 pnt2 fpnt) ; close polyline (command "c") (command ".ZOOM" "e") ; extrude to height (command ".EXTRUDE" "last" "" zthk) ; versions prior to 2007 require the taper parameter ;(command ".EXTRUDE" "last" "" zthk "") ; add to list (setq llist (ssadd (entlast))) ; floor mass (setq pnt1 (list (nth 0 pnt0) (+ (nth 1 pnt0) ymaxoff) zelev)) (setq pnt2 (list (+ (nth 0 pnt0) (* xtimes xyside)) (+ (nth 1 pnt0) (* ytimes xyside)) zelev)) (command ".RECTANGLE" pnt1 pnt2) ; extrude to height (command ".EXTRUDE" "last" "" zheight) ; versions prior to 2007 require the taper parameter ;(command ".EXTRUDE" "last" "" zheight "") ; add to list (setq llist (ssadd (entlast) llist)) ; union level (command ".UNION" llist "") ; inc levels elev (setq zelev (+ zelev zheight)) ; inc ang (setq sxang (+ sxang angy)) ) (princ) ) ;-------------------------------------------------------------------------- (defun xprog04c () (graphscr) ; set start point (setq pnt0 (list 0 0 0)) (setq xyside (getdist pnt0 "\nEnter XY side:")) (setq xtimes (getint "\nEnter number X repeats:")) (setq ytimes (getint "\nEnter number Y repeats:")) (setq zheight (getdist "\Enter Z height: ")) (setq zthk (getdist "\Enter extrusion height: ")) (setq nlevels (getint "\Enter number of levels: ")) (setq ymaxoff (getdist "\Enter max Y offset: ")) (setq angy (getreal "\Enter angle multiple: ")) (setq ycycles (getreal "\Enter number of curve cycles: ")) ; start Z location (setq zelev 0.0) (repeat nlevels ; start edge (command ".PLINE") ; curve angles (setq xang (* (fix (* (rn) 24)) angy)) (setq xanginc (/ (* 360.0 ycycles) xtimes)) (setq xloc (nth 0 pnt0)) (setq yloc (nth 1 pnt0)) (setq xnum 1) (repeat (+ xtimes 1) ; compute Y offset based on curve (setq yoff (* (sin (dtr xang)) ymaxoff)) (setq npnt (list xloc (+ yloc yoff) zelev)) (command npnt) ; save first pt (if (= xnum 1) (setq fpnt npnt)) ; inc x location and angs (setq xloc (+ xloc xyside)) (setq xang (+ xang xanginc)) (setq xnum (+ xnum 1)) ) ; level corner pts (setq pnt1 (list (+ (nth 0 pnt0) (* xtimes xyside)) (+ (nth 1 pnt0) (* ytimes xyside)) zelev)) (setq pnt2 (list (nth 0 pnt0) (+ (nth 1 pnt0) (* ytimes xyside)) zelev)) (command pnt1 pnt2 fpnt) ; close polyline (command "c") (command ".ZOOM" "e") ; extrude to height (command ".EXTRUDE" "last" "" zthk) ; versions prior to 2007 require the taper parameter ;(command ".EXTRUDE" "last" "" zheight "") ; inc levels elev (setq zelev (+ zelev zheight)) ) (princ) ) ;-------------------------------------------------------------------------- ;-------------------------------------------------------------------------- ;-------------------------------------------------------------------------- (defun prog05 () (graphscr) (command ".ERASE" "all" "") ; set start point (setq pnt0 (list 0 0 0)) (setq radx (/ (getdist "\nEnter X distance:") 2)) (setq rady (/ (getdist "\nEnter Y distance:") 2)) (setq zheight (getdist "\Enter Z height: ")) (setq zthk (getdist "\Enter slab thickness: ")) (setq nlevels (getint "\Enter number of levels: ")) (setq ymaxoff (getdist "\Enter max Y offset: ")) (setq angy (getreal "\Enter angle multiple: ")) (setq ycycles (getreal "\Enter number of curve cycles: ")) ; segments (setq xtimes (fix (/ 360.0 2))) ; start angle (setq sxang (* (fix (* (rn) 24)) angy)) (setq xanginc (/ (* 360.0 ycycles) xtimes)) ; start Z location (setq zelev 0.0) (setq xloc (nth 0 pnt0)) (setq yloc (nth 1 pnt0)) ; total area and perimeter (setq totalarea 0.0) (setq totalperm 0.0) (repeat nlevels ; start outline (command ".PLINE") ; curve face start x location (setq xang sxang) (setq rang 0.0) (setq ranginc (/ 360.0 xtimes)) (setq xnum 1) (repeat (+ xtimes 1) ; radius offset (setq roff (* (+ (sin (dtr (* xang 2))) (sin (dtr (* xang 3)))) ymaxoff)) ; ellipse (setq xoff (* (+ radx roff) (cos (dtr rang)))) (setq yoff (* (+ rady roff) (sin (dtr rang)))) (setq npnt (list (+ xloc xoff) (+ yloc yoff) zelev)) (command npnt) ; save first pt (if (= xnum 1) (setq fpnt npnt)) ; inc segment (setq rang (+ rang ranginc)) (setq xang (+ xang xanginc)) (setq xnum (+ xnum 1)) ) ; close (command "c") (command ".ZOOM" "e") ; compute area (command ".AREA" "o" "last") (setq flrarea (/ (getvar "AREA") 144)) (setq flrperm (/ (getvar "PERIMETER") 12)) ; acum floor and building surface (setq totalarea (+ totalarea flrarea)) (setq totalperm (+ totalperm flrperm)) ; extrude to height (command ".EXTRUDE" "last" "" zthk) ; versions prior to 2007 require the taper parameter ;(command ".EXTRUDE" "last" "" zheight "") ; inc levels elev (setq zelev (+ zelev zheight)) ; inc start angle (setq sxang (+ sxang angy)) ) (princ "\nTotal area: ") (princ (rtos totalarea 2 0)) (princ " Perimeter: ") (princ (rtos totalperm 2 0)) (princ) ) ;-------------------------------------------------------------------------- ;-------------------------------------------------------------------------- (defun prog05a () (graphscr) (command ".ERASE" "all" "") ; set start point (setq pnt0 (list 0 0 0)) (setq radx (/ (getdist "\nEnter X distance:") 2)) (setq rady (/ (getdist "\nEnter Y distance:") 2)) (setq zheight (getdist "\Enter Z height: ")) (setq zthk (getdist "\Enter slab thickness: ")) (setq nlevels (getint "\Enter number of levels: ")) (setq ymaxoff (getdist "\Enter max Y offset: ")) (setq angy (getreal "\Enter angle multiple: ")) (setq ycycles (getreal "\Enter number of curve cycles: ")) ; segments (setq xtimes (fix (/ 360.0 2))) ; start angle (setq sxang (* (fix (* (rn) 24)) angy)) (setq xanginc (/ (* 360.0 ycycles) xtimes)) ; start Z location (setq zelev 0.0) (setq xloc (nth 0 pnt0)) (setq yloc (nth 1 pnt0)) ; total area and perimeter (setq totalarea 0.0) (setq totalperm 0.0) (repeat nlevels ; start outline (command ".PLINE") ; curve face start x location (setq xang sxang) (setq rang 0.0) (setq ranginc (/ 360.0 xtimes)) (setq xnum 1) (repeat (+ xtimes 1) ; radius offset (setq roff (* (+ (sin (dtr xang)) (sin (dtr (* xang 2)))) ymaxoff)) ; superellipse (setq xoff (* (+ radx roff) (* (expt (abs (cos (dtr rang))) 0.5) (sign (cos (dtr rang)))))) (setq yoff (* (+ rady roff) (* (expt (abs (sin (dtr rang))) 0.5) (sign (sin (dtr rang)))))) (setq npnt (list (+ xloc xoff) (+ yloc yoff) zelev)) (command npnt) ; save first pt (if (= xnum 1) (setq fpnt npnt)) ; inc segment (setq rang (+ rang ranginc)) (setq xang (+ xang xanginc)) (setq xnum (+ xnum 1)) ) ; close (command "c") (command ".ZOOM" "e") ; compute area (command ".AREA" "o" "last") (setq flrarea (/ (getvar "AREA") 144)) (setq flrperm (/ (getvar "PERIMETER") 12)) ; acum floor and building surface (setq totalarea (+ totalarea flrarea)) (setq totalperm (+ totalperm flrperm)) ; extrude to height (command ".EXTRUDE" "last" "" zthk) ; versions prior to 2007 require the taper parameter ;(command ".EXTRUDE" "last" "" zheight "") ; inc levels elev (setq zelev (+ zelev zheight)) ; inc start angle (setq sxang (+ sxang angy)) ) (princ "\nTotal area: ") (princ (rtos totalarea 2 0)) (princ " Perimeter: ") (princ (rtos totalperm 2 0)) (princ) ) ;-------------------------------------------------------------------------- (defun prog06 () (graphscr) (command ".ERASE" "all" "") ; set start point (setq pnt0 (list 0 0 0)) (setq radx (/ (getdist "\nEnter X distance:") 2)) (setq rady (/ (getdist "\nEnter Y distance:") 2)) (setq zheight (getdist "\Enter Z height: ")) (setq nlevels (getint "\Enter number of levels: ")) (setq nlocs (getint "\Enter number of locations: ")) (setq cradmin (getdist "\Enter min radius: ")) (setq cradmax (getdist "\Enter max radius: ")) ; locations along ellipse (setq rang 0.0) (setq ranginc (/ 360.0 nlocs)) (setq xloc (nth 0 pnt0)) (setq yloc (nth 1 pnt0)) (repeat nlocs ; ellipse (setq xoff (* radx (cos (dtr rang)))) (setq yoff (* rady (sin (dtr rang)))) (setq pntc (list (+ xloc xoff) (+ yloc yoff) 0.0)) ; radius (setq crad (+ cradmin (* (rn) (- cradmax cradmin)))) (command ".CIRCLE" pntc crad) ; extrude to height (command ".EXTRUDE" "last" "" zheight) ; versions prior to 2007 require the taper parameter ;(command ".EXTRUDE" "last" "" zheight "") (command ".ZOOM" "e") ; inc ang location (setq rang (+ rang ranginc)) ) ; center core (command ".ELLIPSE" "c" pnt0 (list radx 0 0) rady) ; extrude to height (command ".EXTRUDE" "last" "" zheight) ; versions prior to 2007 require the taper parameter ;(command ".EXTRUDE" "last" "" zheight "") ; union all (command ".UNION" "all" "") ; copy to full height (setq llist (ssadd (entlast))) ; set above first copy (setq zelev zheight) (repeat (- nlevels 1) (command ".COPY" llist "" pnt0 (list (nth 0 pnt0) (nth 1 pnt0) zelev)) (command ".ZOOM" "e") ; inc height (setq zelev (+ zelev zheight)) ) (princ) ) ;-------------------------------------------------------------------------- (defun prog06a () (graphscr) (command ".ERASE" "all" "") ; set start point (setq pnt0 (list 0 0 0)) (setq radx (/ (getdist "\nEnter X distance:") 2)) (setq rady (/ (getdist "\nEnter Y distance:") 2)) (setq zheight (getdist "\Enter Z height: ")) (setq nlevels (getint "\Enter number of levels: ")) (setq nlocs (getint "\Enter number of locations: ")) (setq cradmin (getdist "\Enter min radius: ")) (setq cradmax (getdist "\Enter max radius: ")) ; locations along ellipse (setq rang 0.0) (setq ranginc (/ 360.0 nlocs)) (setq xloc (nth 0 pnt0)) (setq yloc (nth 1 pnt0)) (repeat nlocs ; ellipse (setq xoff (* radx (cos (dtr rang)))) (setq yoff (* rady (sin (dtr rang)))) ; radius (setq crad (+ cradmin (* (rn) (- cradmax cradmin)))) ; get bottom elev (setq slevel (fix (* (rn) nlevels))) (setq nlevel (+ (fix (* (rn) (- nlevels slevel))) 1)) (setq zelev (* slevel zheight)) (repeat nlevel (setq pntc (list (+ xloc xoff) (+ yloc yoff) zelev)) (command ".CIRCLE" pntc crad) ; extrude to height (command ".EXTRUDE" "last" "" zheight) ; versions prior to 2007 require the taper parameter ;(command ".EXTRUDE" "last" "" zheight "") (command ".ZOOM" "e") (setq zelev (+ zelev zheight)) ) ; inc x location (setq rang (+ rang ranginc)) ) ; center core (setq zelev 0.0) (repeat nlevels (command ".ELLIPSE" "c" (list (nth 0 pnt0) (nth 1 pnt0) zelev) (list radx 0 zelev) rady) (command ".EXTRUDE" "last" "" zheight) ; versions prior to 2007 require the taper parameter ;(command ".EXTRUDE" "last" "" zheight "") (setq zelev (+ zelev zheight)) ) (princ) ) ;-------------------------------------------------------------------------- (defun prog07 () (graphscr) (command ".ERASE" "all" "") ; set start point (setq pnt0 (list 0 0 0)) (setq xyside (getdist pnt0 "\nEnter XY side:")) (setq xtimes (getint "\nEnter number X repeats:")) (setq ytimes (getint "\nEnter number Y repeats:")) (setq zheight (getdist "\nEnter Z height: ")) (setq nlevels (getint "\nEnter number of levels: ")) (setq cminx (getdist "\nEnter cube min size: ")) (setq cmaxx (getdist "\nEnter cube max size: ")) (setq angrot (getreal "\Enter angle multiple: ")) ; start Z location (setq zelev 0.0) (repeat nlevels ; level block (setq pnt1 (list (+ (nth 0 pnt0) (/ xyside 2.0)) (+ (nth 1 pnt0) (/ xyside 2.0)) zelev)) (setq pnt2 (list (+ (nth 0 pnt1) (- (* xtimes xyside) xyside)) (+ (nth 1 pnt1) (- (* ytimes xyside) xyside)) zelev)) (command ".RECTANGLE" pnt1 pnt2) (command ".ZOOM" "e") (command ".EXTRUDE" "last" "" zheight) ; versions prior to 2007 require the taper parameter ;(command ".EXTRUDE" "last" "" zheight "") (setq llist (ssadd (entlast))) ; start y location (setq ynum 1) (setq yloc 0) (repeat ytimes ; start x location (setq xnum 1) (setq xloc 0) (repeat xtimes (if (or (or (or (= ynum 1) (= ynum ytimes)) (= xnum 1)) (= xnum xtimes)) (progn ; lower corner pt (setq pnt1 (list xloc yloc zelev)) ; center of module (setq pnt2 (list (+ (nth 0 pnt1) (/ xyside 2)) (+ (nth 1 pnt1) (/ xyside 2)) (+ zelev (/ zheight 2)))) ; cube dimension (setq cx (+ cminx (* (fix (* (rn) (+ (/ (- cmaxx cminx) xyside) 1))) xyside))) ; rotation (setq crang (* (fix (* (rn) angrot)) angrot)) ; draw cube (command ".BOX" "ce" pnt2 "c" cx) (command ".ZOOM" "e") ; rotate (command ".ROTATE3D" "last" "" "z" pnt2 (+ crang 0.0001)) ; add to list (setq llist (ssadd (entlast) llist)) )) ; inc x location (setq xloc (+ xloc xyside)) (setq xnum (+ xnum 1)) ) ; union level (command ".UNION" "all" "") ; inc y location (setq yloc (+ yloc xyside)) (setq ynum (+ ynum 1)) ) ; inc levels elev (setq zelev (+ zelev zheight)) ) ; union cubes (command ".UNION" "all" "") ; slice at ground (command ".SLICE" "all" "" "XY" (list 0 0 0) (list 0 0 1)) (princ) ) ;-------------------------------------------------------------------------- (defun prog07a () (graphscr) (command ".ERASE" "all" "") ; set start point (setq pnt0 (list 0 0 0)) (setq xyside (getdist pnt0 "\nEnter XY side:")) (setq radx (/ (getdist "\nEnter X distance:") 2)) (setq rady (/ (getdist "\nEnter Y distance:") 2)) (setq zheight (getdist "\nEnter Z height: ")) (setq nlevels (getint "\nEnter number of levels: ")) (setq nlocs (getint "\Enter number of locations: ")) (setq cminx (getdist "\nEnter cube min size: ")) (setq cmaxx (getdist "\nEnter cube max size: ")) (setq angrot (getreal "\Enter angle multiple: ")) ; start Z location (setq zelev 0.0) (repeat nlevels ; level block (command ".ELLIPSE" "c" (list (nth 0 pnt0) (nth 1 pnt0) zelev) (list radx 0 zelev) rady) (command ".ZOOM" "e") (command ".EXTRUDE" "last" "" zheight) ; versions prior to 2007 require the taper parameter ;(command ".EXTRUDE" "last" "" zheight "") (setq llist (ssadd (entlast))) ; locations along ellipse (setq rang 0.0) (setq ranginc (/ 360.0 nlocs)) (setq xloc (nth 0 pnt0)) (setq yloc (nth 1 pnt0)) (repeat nlocs ; ellipse (setq xoff (* radx (cos (dtr rang)))) (setq yoff (* rady (sin (dtr rang)))) ; center of module (setq pnt2 (list (+ xloc xoff) (+ yloc yoff) (+ zelev (/ zheight 2)))) ; cube dimension (setq cx (+ cminx (* (fix (* (rn) (+ (/ (- cmaxx cminx) xyside) 1))) xyside))) ; rotation (setq crang (* (fix (* (rn) angrot)) angrot)) ; draw cube (command ".BOX" "ce" pnt2 "c" cx) (command ".ZOOM" "e") ; rotate (command ".ROTATE3D" "last" "" "z" pnt2 (+ crang 0.0001)) ; add to list (setq llist (ssadd (entlast) llist)) ; inc ang (setq rang (+ rang ranginc)) ) ; union level (command ".UNION" "all" "") ; inc levels elev (setq zelev (+ zelev zheight)) ) ; union cubes (command ".UNION" "all" "") ; slice at ground (command ".SLICE" "all" "" "XY" (list 0 0 0) (list 0 0 1)) (princ) ) ;-------------------------------------------------------------------------- ;-------------------------------------------------------------------------- (defun prog07b () (graphscr) (command ".ERASE" "all" "") ; set start point (setq pnt0 (list 0 0 0)) (setq xyside (getdist pnt0 "\nEnter XY side:")) (setq radx (/ (getdist "\nEnter X distance:") 2)) (setq rady (/ (getdist "\nEnter Y distance:") 2)) (setq zheight (getdist "\nEnter Z height: ")) (setq nlevels (getint "\nEnter number of levels: ")) (setq nlocs (getint "\Enter number of locations: ")) (setq cminx (getdist "\nEnter cube min size: ")) (setq cmaxx (getdist "\nEnter cube max size: ")) (setq angrot (getreal "\Enter angle multiple: ")) ; start Z location (setq zelev 0.0) (repeat nlevels ; level block (command ".ELLIPSE" "c" (list (nth 0 pnt0) (nth 1 pnt0) zelev) (list radx 0 zelev) rady) (command ".ZOOM" "e") (command ".EXTRUDE" "last" "" zheight) ; versions prior to 2007 require the taper parameter ;(command ".EXTRUDE" "last" "" zheight "") (setq llist (ssadd (entlast))) ; locations along ellipse (setq rang 0.0) (setq ranginc (/ 360.0 nlocs)) (setq xloc (nth 0 pnt0)) (setq yloc (nth 1 pnt0)) (repeat nlocs ; ellipse (setq xoff (* radx (cos (dtr rang)))) (setq yoff (* rady (sin (dtr rang)))) ; center of module (setq pnt2 (list (+ xloc xoff) (+ yloc yoff) (+ zelev (/ zheight 2)))) ; cube dimension (setq cx (+ cminx (* (fix (* (rn) (+ (/ (- cmaxx cminx) xyside) 1))) xyside))) ; rotation (setq crang (* (fix (* (rn) angrot)) angrot)) ; draw cube (command ".BOX" "ce" pnt2 "c" cx) (command ".ZOOM" "e") ; rotate (command ".ROTATE3D" "last" "" "z" pnt2 (+ crang 0.0001)) ; add to list (setq llist (ssadd (entlast) llist)) ; inc ang (setq rang (+ rang ranginc)) ) ; union level (command ".UNION" "all" "") ; inc levels elev (setq zelev (+ zelev zheight)) ) ; union cubes (command ".UNION" "all" "") ; slice at ground (command ".SLICE" "all" "" "XY" (list 0 0 0) (list 0 0 1)) ; generate floor plans (setq totalarea 0.0) (setq totalperm 0.0) (setq zelev 0.0) (repeat nlevels ; get section (command ".SECTION" "all" "" "xy" (list 0 0 zelev)) ; move it (command ".MOVE" "last" "" (list 0 0 zelev) (list (+ (nth 0 pnt0) (* radx 3.0)) (nth 1 pnt0) zelev)) ; compute area (command ".AREA" "o" "last") (setq flrarea (/ (getvar "AREA") 144)) (setq flrperm (/ (getvar "PERIMETER") 12)) ; acum floor and building surface (setq totalarea (+ totalarea flrarea)) (setq totalperm (+ totalperm flrperm)) ; inc height (setq zelev (+ zelev zheight)) ) (command ".ZOOM" "e") (princ "\nTotal area: ") (princ (rtos totalarea 2 0)) (princ " Perimeter: ") (princ (rtos totalperm 2 0)) (princ) ) ;-------------------------------------------------------------------------- ;-------------------------------------------------------------------------- (defun prog08 () (graphscr) (command ".ERASE" "all" "") ; set start point (setq pnt0 (list 0 0 0)) (setq xyside (getdist pnt0 "\nEnter XY side:")) (setq xtimes (getint "\nEnter number X repeats:")) (setq ytimes (getint "\nEnter number Y repeats:")) (setq zheight (getdist "\nEnter Z height: ")) (setq nlevels (getint "\nEnter number of levels: ")) (setq cminx (getdist "\nEnter cube min size: ")) (setq cmaxx (getdist "\nEnter cube max size: ")) (setq angrot (getreal "\Enter angle multiple: ")) (setq ntimes (getint "\nEnter number of random placements: ")) ; number of placements (repeat ntimes ; random location (setq xoff (* (fix (* (rn) xtimes)) xyside)) (setq yoff (* (fix (* (rn) ytimes)) xyside)) (setq zelev (* (fix (* (rn) nlevels)) zheight)) ; center of module (setq pnt2 (list (+ (nth 0 pnt0) xoff) (+ (nth 1 pnt0) yoff) (+ (nth 2 pnt0) zelev))) ; cube dimension (setq cx (+ cminx (* (fix (* (rn) (+ (/ (- cmaxx cminx) xyside) 1))) xyside))) ; rotation (setq crang (* (fix (* (rn) angrot)) angrot)) ; draw cube (command ".BOX" "ce" pnt2 "c" cx) (command ".ZOOM" "e") ; rotate (command ".ROTATE3D" "last" "" "z" pnt2 (+ crang 0.0001)) ) ; union cubes (command ".UNION" "all" "") ; slice at ground (command ".SLICE" "all" "" "XY" (list 0 0 0) (list 0 0 1)) (princ) ) ;-------------------------------------------------------------------------- (defun prog08a () (graphscr) (command ".ERASE" "all" "") ; set start point (setq pnt0 (list 0 0 0)) (setq xyside (getdist pnt0 "\nEnter XY side:")) (setq xtimes (getint "\nEnter number X repeats:")) (setq ytimes (getint "\nEnter number Y repeats:")) (setq zheight (getdist "\nEnter Z height: ")) (setq nlevels (getint "\nEnter number of levels: ")) (setq cminx (getdist "\nEnter cube min size: ")) (setq cmaxx (getdist "\nEnter cube max size: ")) (setq angrot (getreal "\Enter angle multiple: ")) (setq ntimes (getint "\nEnter number of random placements: ")) ; number of placements (repeat ntimes ; random location (setq xoff (* (fix (* (rn) xtimes)) xyside)) (setq yoff (* (fix (* (rn) ytimes)) xyside)) (setq zelev (* (fix (* (rn) nlevels)) zheight)) ; center of module (setq pnt2 (list (+ (nth 0 pnt0) xoff) (+ (nth 1 pnt0) yoff) (+ (nth 2 pnt0) zelev))) ; cube dimension (setq cx (+ cminx (* (fix (* (rn) (+ (/ (- cmaxx cminx) xyside) 1))) xyside))) ; rotation (setq crang (* (fix (* (rn) angrot)) angrot)) ; draw cube (command ".BOX" "ce" pnt2 "c" cx) (command ".ZOOM" "e") ; rotate (command ".ROTATE3D" "last" "" "z" pnt2 (+ crang 0.0001)) ) ; union cubes (command ".UNION" "all" "") ; slice at ground (command ".SLICE" "all" "" "XY" (list 0 0 0) (list 0 0 1)) ; slice at sides (command ".SLICE" "all" "" "YZ" (list 0 0 0) (list 1 0 0)) (command ".SLICE" "all" "" "ZX" (list 0 0 0) (list 0 1 0)) (command ".SLICE" "all" "" "YZ" (list (* xtimes xyside) 0 0) (list 1 0 0)) (command ".SLICE" "all" "" "ZX" (list 0 (* ytimes xyside) 0) (list 0 1 0)) ; generate floor plans (setq totalarea 0.0) (setq totalperm 0.0) (setq zelev 0.0) (repeat nlevels ; get section (command ".SECTION" "all" "" "xy" (list 0 0 zelev)) ; move it (command ".MOVE" "last" "" (list 0 0 zelev) (list (+ (nth 0 pnt0) (* (* xyside xtimes) 1.5)) (nth 1 pnt0) zelev)) ; compute area (command ".AREA" "o" "last") (setq flrarea (/ (getvar "AREA") 144)) (setq flrperm (/ (getvar "PERIMETER") 12)) ; acum floor and building surface (setq totalarea (+ totalarea flrarea)) (setq totalperm (+ totalperm flrperm)) ; inc height (setq zelev (+ zelev zheight)) ) (command ".ZOOM" "e") (princ "\nTotal area: ") (princ (rtos totalarea 2 0)) (princ " Perimeter: ") (princ (rtos totalperm 2 0)) (princ) ) ;-------------------------------------------------------------------------- ;-------------------------------------------------------------------------- ;-------------------------------------------------------------------------- ;-------------------------------------------------------------------------- ;-------------------------------------------------------------------------- ; load solid modeling DLL (arxload "geom3d") ;--------------------------------------------------------------------------