; RoomLabel labels with rectangular pline with dimensions and area Note: proper TextSize needs to be set ; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/how-do-i-edit-this-lisp-to-get-a-label-with-room-dimensions-and/m-p/13162087/thread-id/475029 ; modified from: ; pBe Jan 2021 (defun c:RoomLabel (/ _Imperial _StrcatW Ent Entobj h lst Mtx Mtxobj nc opt p Roomname selrec seltxt str tmpEnt tmpDist1 tmpDist2 tmpPt txFont v VerPoints ) (vl-load-com) (defun _Imperial (v) (rtos (cvunit v "millimeter" "inch") 4 0)) (defun _StrcatW (l f) (substr (apply 'strcat (mapcar '(lambda (s) (strcat f s)) l)) 2 ) ) (defun seltxt (/ s) (while (not s) (princ"\nSelect MText...") (if(not(setq s (ssget "_+.:E:S" '((0 . "MTEXT")))))(setq s nil)) ) (ssname s 0) ) ; selrec function to make single selection on only rectangular closed plines ; modified from: ; https://stackoverflow.com/questions/61619896/autolisp-trying-to-select-lwpolyline-but-only-rectangles-how-do-i-do-that (defun selrec ( / a b c d e s) (while (not s) (princ"\nSelect Rectangle...") (if(setq s (ssget "_+.:E:S" '((0 . "LWPOLYLINE") (90 . 4) (-4 . "&=") (70 . 1)))) (progn (setq e (ssname s 0)) (mapcar 'set '(a b c d) (mapcar 'cdr (vl-remove-if-not '(lambda ( x ) (= 10 (car x))) (entget e)))) (if (not (and (equal (distance a b) (distance c d) 1e-8) (equal (distance b c) (distance a d) 1e-8) (equal (distance a c) (distance b d) 1e-8) ) ) (setq s nil) e ) ) ; progn (setq s nil) ) ; if ) ; while ) (setvar 'dynmode 3) (setq lst '(("1" " LIVING ROOM")("2" " DINING")("3" " KITCHEN")("4" " WET KITCHEN")("5" " UTILITY")("6" " BEDROOM")("7" " BATHROOM") ("8" " MASTER BEDROOM")("9" " MASTER BATHROOM")("10" " POWDER ROOM")("11" " FAMILY ROOM") ("12" " FOYER")("13" " POOJA")("14" " BALCONY+DECK") ("15" " MAID'S ROOM")("16" " MAID'S TOILET")("17" " WIW")("T" " Type")) ) ;; if Bahnschrift in not the current textstyle or does not exist on the drawing ;; ;; the default textstyle would be standard, text height = current TEXTSIZE ;; (setq txFont (if (member (Cdr (assoc 2 (tbLsearch "style" (getvar 'textstyle)))) '("BH-Light" "BH-Medium") ) (list "{\\fSwiss721 Cn BT|b0|i0|c0|p10;" "\\P\\fSwiss721 Cn BT|b0|i0|c0|p10;" "}" ) (list "{\\fArial|b0|i0|c0|p10;" "}\\P" "") ) ) (initget 1 (_strcatw (mapcar 'car lst) " ")) (setq opt (getkword (strcat "\nChoose Room name [" (_strcatw (mapcar 'strcat (mapcar 'car lst) (mapcar 'cadr lst)) "/") "]: " ) ) ) (setq Roomname (cond ((= opt "T")(getstring t "\nTYPE ROOM NAME: ")) ((substr (cadr (assoc opt lst)) 2)) ;; more options here in the future ;;; ) ) (if ; LabelRec length and width of rectangle ; modified from: ; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/length-and-width-of-rectangle-as-text/m-p/1369620/highlight/true#M184418 (and (setq Ent (selrec)) ; selects only rectangles ; (setq Mtx (seltxt)) ; selects text ) (progn (setq EntData (entget Ent) Entobj (vlax-ename->vla-object Ent) ; Mtxobj (vlax-ename->vla-object Mtx) VerPoints (vlax-get Entobj 'Coordinates) p (osnap (vlax-curve-getStartPoint Ent) "gcen") ; use built-in geocenter osnap to get centerpoint of rectangle ) (if (= (length VerPoints) 8) (progn (setq tmpDist1 (distance (list (nth 0 VerPOints) (nth 1 VerPoints)) (list (nth 2 VerPoints) (nth 3 VerPoints)))) (setq tmpDist2 (distance (list (nth 2 VerPOints) (nth 3 VerPoints)) (list (nth 4 VerPoints) (nth 5 VerPoints)))) (if (< tmpDist1 tmpDist2) ; get height & width (setq h tmpDist2 v tmpDist1) (setq h tmpDist1 v tmpDist2) ) (setq str (strcat (car txFont) Roomname (cadr txFont) (_Imperial h) " x " (_Imperial v) "\\P" "%<\\AcObjProp Object(%<\\_ObjId " (itoa (vla-get-Objectid Entobj)) ">%).Area \\f \"%lu2%pr2%ps[, SQ. FT.]%ct8[1.076389999999999E-005]\">%" (caddr txFont) ) ) ;; make mtext object base on current TEXTSIZE for height (entmakex (list (cons 0 "MTEXT") (cons 100 "AcDbEntity") (cons 100 "AcDbMText") (cons 10 (trans p 1 0)) (cons 1 "MTEXT") (cons 41 (- (car p)(car p))) (cons 71 5) (cons 72 5) (cons 73 1)) ) (setq Mtxobj (vlax-ename->vla-object (entlast))) (vlax-put-property Mtxobj 'textstring str) ; place onto Mtxt ) ; progn ) ; if ) ; progn ) ; if (princ) ) ; defun