Message 1 of 9
Lisp Routine That Automatically Adds MTEXT of AEC Door and Window Sizes
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi, I am trying to write a routine that will automatically add door and window tags with the sizes, that is also edit-able if I need to revise to say "Per Elevation", for example. Here is what I have and I cannot get it to work:
(defun c:AddWindowDoorSizes (/ doc modelSpace windows doors windowObj doorObj width height insertPoint mtextObj sizeText)
;; Get the active document
(setq doc (vla-get-ActiveDocument (vlax-get-Acad-Object)))
;; Get ModelSpace
(setq modelSpace (vla-get-ModelSpace doc))
;; Loop through all entities in ModelSpace
(vlax-for obj modelSpace
(setq entityType (cdr (assoc 0 (entget (vlax-vla-object->ename obj)))))
;; Check for AEC windows
(if (equal entityType "AEC_WINDOW")
(progn
(setq windowObj (vlax-vla-object->vla-object obj))
;; Get width and height
(setq width (vla-get-Width windowObj))
(setq height (vla-get-Height windowObj))
;; Ensure width and height are valid
(if (and (numberp width) (numberp height))
(progn
;; Get insertion point
(setq insertPoint (vlax-get windowObj 'InsertionPoint))
;; Create the size text
(setq sizeText (strcat (rtos width 2 0) " x " (rtos height 2 0)))
;; Add MText to ModelSpace
(setq mtextObj (vla-AddMText modelSpace
(vlax-3d-point (car insertPoint) (+ (cadr insertPoint) 100) 0) ;; Offset above the window
0 ;; Automatic width
sizeText)) ;; Size text
;; Set MText properties
(vla-put-Height mtextObj 2.5) ;; Height of MText
(vla-put-Justification mtextObj acMTextCenter) ;; Center justification
(vla-put-Layer mtextObj "0") ;; Set layer (adjust if necessary)
)
)
)
)
;; Check for AEC doors
(if (equal entityType "AEC_DOOR")
(progn
(setq doorObj (vlax-vla-object->vla-object obj))
;; Get width and height
(setq width (vla-get-Width doorObj))
(setq height (vla-get-Height doorObj))
;; Ensure width and height are valid
(if (and (numberp width) (numberp height))
(progn
;; Get insertion point
(setq insertPoint (vlax-get doorObj 'InsertionPoint))
;; Create the size text
(setq sizeText (strcat (rtos width 2 0) " x " (rtos height 2 0)))
;; Add MText to ModelSpace
(setq mtextObj (vla-AddMText modelSpace
(vlax-3d-point (car insertPoint) (+ (cadr insertPoint) 100) 0) ;; Offset above the door
0 ;; Automatic width
sizeText)) ;; Size text
;; Set MText properties
(vla-put-Height mtextObj 2.5) ;; Height of MText
(vla-put-Justification mtextObj acMTextCenter) ;; Center justification
(vla-put-Layer mtextObj "0") ;; Set layer (adjust if necessary)
)
)
)
)
)
(princ "\nWindow and Door sizes added as text.")
(princ)
)
(princ "\nType 'AddWindowDoorSizes' to add size labels to all AEC windows and doors.")
(princ)
Thank you.