;; Studs - every 16" ;; An example scroll from Bill Kramer, Autodesk Toplines ;; ;; This function will draw a basic frame for a wall using ;; standard sizes for the studs. The rules are to place ;; a stud every 16" along a line with additional wood ;; on the top and bottom. ;; ;; DO NOT USE THIS FUNCTION FOR PRODUCTION UNTIL YOU ;; UNDERSTAND WHAT IT IS DOING! It is intended for ;; educational purposes only.;; ;; Demonstrates the use of ENTMAKE, list substitution, while loop, ;; point calculations using polar, angle, and distance. Also ;; shows how to create a block using ENTMAKE. ;; ;;--------------------------------------------------------------------- ;; ;; Establish Constant Sizes - all values in Inches ;; (setq L2x4 93.0 ;;length of a 2x4 (8' minus 3") W2x4 3.75 ;;the "4" cut size H2x4 1.75 ;;the "2" cut size Span 16.0 ;;16" center to center ) ;;--------------------------------------------------------------------- (defun C:STUDS ( / EN ;entity selection EL ;entity data list of line selected LL ;length of the selected line AA ;angle of the selected line P1 ;Placement point DD ;Running distance value BLK ;entity data list of insert block ) (setq EN (entsel "\nPick wall line: ")) ;operator input (if EN ;verify entity selection (progn (setq EL (entget (car EN))) ;get entity data list (if (= (cdr (assoc 0 EL)) "LINE") ;verify it is a LINE object (progn (setq P1 (midpoint (cdr (assoc 10 EL)) (cdr (assoc 11 EL))) AA (angle (cdr (assoc 10 EL)) ;angle of line (cdr (assoc 11 EL))) ) ;; ;; Show side that studs will be placed on by default (grdraw P1 (polar P1 (+ AA (/ PI 2.0)) (* 2.0 W2x4)) 1) ;; ;; User selection of whether to reverse line direction (initget 0 "Yes No") (setq TMP (getkword "\nPlace studs to side of line shown? : ")) (if (null TMP) (setq TMP "Yes")) (if (= Tmp "No") ;;flip the data around, swap in entity data list (setq Tmp (cdr (assoc 10 EL)) P1 (cdr (assoc 11 EL)) EL (subst (cons 10 P1) (assoc 10 EL) EL) EL (subst (cons 11 Tmp) (assoc 11 EL) EL) AA (angle P1 Tmp) )) ;; (setq LL (distance (cdr (assoc 10 EL)) ;length of line (cdr (assoc 11 EL))) P1 (polar (cdr (assoc 10 EL)) ;1st stud point AA (/ H2x4 2.0)) ;locate first stud DD (/ H2x4 2.0) ;distance to first stud BLK (list ;set up prototype block insert entity data list '(0 . "INSERT") '(2 . "STUD2x4") '(8 . "0") '(10 0.0 0.0 0.0) (cons 38 H2x4) ;place studs one board off floor '(50 . 0.0) ;rotation angle '(41 . 1.0) ;scale factors '(42 . 1.0) '(43 . 1.0) ) BLK (subst (cons 50 AA) ;adjust rotation factor example (assoc 50 BLK) BLK) ) ;; ;; Create blocks if they do not already exist in drawing ;; (if (null (tblsearch "BLOCK" "STUD2x4")) (create_stud_block)) (if (null (tblsearch "BLOCK" "Beam2x4")) (create_beam_block)) ;; ;; Draw in the studs along the line ;; (while (< DD LL) (setq BLK (subst (cons 10 P1) (assoc 10 BLK) BLK)) (entmake BLK) (setq P1 (polar P1 AA Span) DD (+ DD Span) ) ) ;; ;; Add last stud. ;; (setq P1 (polar (cdr (assoc 11 EL)) AA -1.0) ;last stud BLK (subst (cons 10 P1) (assoc 10 BLK) BLK)) (entmake BLK) ;; ;; add beams at base and top of studs to complete frame ;; (setq DD L2x4 ;;length of 2x4 BLK (subst '(2 . "Beam2x4") ;;modify prototype insert list (assoc 2 BLK) BLK) P1 (polar (cdr (assoc 10 EL)) ;;first beam at P1 AA (/ L2x4 2.0)) ) ;; ;; repeat beam insertion along the length of the line ;; (while (< DD LL) (setq BLK (subst (cons 10 P1) (assoc 10 BLK) BLK) BLK (subst (cons 38 0.0) (assoc 38 BLK) BLK) ) (entmake BLK) ;;at base (setq BLK (subst (cons 38 (+ H2x4 L2x4)) (assoc 38 BLK) BLK) ) (entmake BLK) ;;at top (setq P1 (polar P1 AA L2x4) DD (+ DD L2x4) ) ) ;; ;; Now add finish beam ;; (setq DD (- 93.0 (- DD LL)) ;partial beam BLK (subst (cons 41 (/ DD L2x4)) (assoc 41 BLK) BLK) BLK (subst (cons 10 (polar (cdr (assoc 11 EL)) AA (/ DD -2.0))) (assoc 10 BLK) BLK) ) (entmake BLK) (setq BLK (subst (cons 38 0.0) (assoc 38 BLK) BLK) ) (entmake BLK) ;; ) (prompt "\nObject selected is not a line!") ) )) (princ) ) ;;--------------------------------------------------- (defun C:HOWMANY () (setq SS1 (ssget "X" '((0 . "INSERT") (2 . "STUD2x4")))) (prompt (strcat "\nStud2x4 count = " (itoa (sslength SS1)))) (setq SS1 (ssget "X" '((0 . "INSERT") (2 . "Beam2x4")))) (prompt (strcat "\nBeam2x4 count = " (itoa (sslength SS1)))) (princ) ) ;;--------------------------------------------------- (defun Create_Stud_Block () (prompt "\nCreating block STUD2x4...") (if (null (entmake '((0 . "BLOCK") (2 . "STUD2x4") (8 . "0") (10 0.0 0.0 0.0) (70 . 0) ) )) (prompt "\nCannot create block!\n") ) (if (null (entmake (list '(0 . "LWPOLYLINE") '(100 . "AcDbEntity") '(67 . 0) '(410 . "Model") '(8 . "0") '(100 . "AcDbPolyline") '(90 . 4) '(70 . 1) '(43 . 0.0) '(38 . 0.0) (cons 39 L2x4) ;;length of wood '(42 . 0.0) (list 10 (/ H2x4 -2.0) 0.0) '(42 . 0.0) (list 10 (/ H2x4 -2.0) W2x4) '(42 . 0.0) (list 10 (/ H2x4 2.0) W2x4) '(42 . 0.0) (list 10 (/ H2x4 2.0) 0.0) '(210 0.0 0.0 1.0) ))) (prompt "\nCannot create LWPOLYLINE") ) (if (null (entmake (list '(0 . "LINE") '(8 . "0") (list 10 (/ H2x4 2.0) 0.0) (list 11 (/ H2x4 -2.0) W2x4) ) )) (prompt "\nCannot create 1st cross line") ) (if (null (entmake (list '(0 . "LINE") '(8 . "0") (list 10 (/ H2x4 -2.0) 0.0) (list 11 (/ H2x4 2.0) W2x4) ) )) (prompt "\nCannot create 1st cross line") ) (entmake '((0 . "ENDBLK") (8 . "0"))) (prompt " finished.") ) ;;--------------------------------------------------------- (defun Create_Beam_Block () (prompt "\nCreating block Beam2x4...") (if (null (entmake '((0 . "BLOCK") (2 . "BEAM2x4") (8 . "0") (10 0.0 0.0 0.0) (70 . 0) ) )) (prompt "\nCannot create block!\n") ) (if (null (entmake (list '(0 . "LWPOLYLINE") '(100 . "AcDbEntity") '(67 . 0) '(410 . "Model") '(8 . "0") '(100 . "AcDbPolyline") '(90 . 4) '(70 . 1) '(43 . 0.0) '(38 . 0.0) (cons 39 H2x4) '(42 . 0.0) (list 10 (/ L2x4 -2.0) 0.0) '(42 . 0.0) (list 10 (/ L2x4 -2.0) W2x4) '(42 . 0.0) (list 10 (/ L2x4 2.0) W2x4) '(42 . 0.0) (list 10 (/ L2x4 2.0) 0.0) '(210 0.0 0.0 1.0) ))) (prompt "\nCannot create LWPOLYLINE") ) (entmake '((0 . "ENDBLK") (8 . "0"))) (prompt " finished.") ) ;;; (defun MidPoint (Pa Pb) (mapcar '(lambda (v1 v2) (/ (+ V1 V2) 2.0)) Pa Pb)) ;;