2012년 12월 30일 일요일

[LISP-LEEMAC] 박스문자 (포스트아이디 : 1136679728372577421)

;; 출 처 : http://www.lee-mac.com/boxtext.html
;; 제 목 : Box Text
;; 버 전 : V1.0
;; 명령어 : BoxText / BT
 ;;BoxText.gif


;;-----------------------=={ Box Text }==---------------------;;
;;                                                            ;;
;;  Frames Text or MText objects with an LWPolyline, with     ;;
;;  optional offset. Works in all UCS/Views.                  ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright ?2010 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;

(defun c:BT nil (c:BoxText))

(defun c:BoxText nil
  ;; ?Lee Mac 2010

  (
    (lambda ( ss off i / e )
      (if ss
        (while (setq e (ssname ss (setq i (1+ i))))
          (entmakex
            (append
              (list
                (cons 0 "LWPOLYLINE")
                (cons 100 "AcDbEntity")
                (cons 100 "AcDbPolyline")
                (assoc 8 (entget e))
                (cons 90 4)
                (cons 70 1)
                (cons 38 (caddr (cdr (assoc 10 (entget e)))))
                (assoc 210 (entget e))
              )
              (mapcar '(lambda ( x ) (cons 10 x)) (LM:GetTextBox e off))
            )
          )
        )
      )
    )
    (ssget '((0 . "TEXT,MTEXT")))
    (setq *o*
      (cond
        (
          (getdist
            (strcat "\nSpecify Offset <"
              (rtos
                (setq *o*
                  (cond ( *o* ) ( (* 0.5 (getvar 'TEXTSIZE)) ))
                )
              )
              "> : "
            )
          )
        )
        ( *o* )
      )
    )
    -1
  )

  (princ)
)

;;---------------------=={ Get Text Box }==-------------------;;
;;                                                            ;;
;;  Returns a point list describing a rectangle framing the   ;;
;;  specified text or mtext entity with optional offset       ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright ?2010 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  ent - Text or MText ename                                 ;;
;;  off - offset (may be zero)                                ;;
;;------------------------------------------------------------;;
;;  Returns:  List of Points (in OCS) describing text frame   ;;
;;------------------------------------------------------------;;

(defun LM:GetTextBox ( ent off / dx lst base rotn norm w h matrix )
  ;; ?Lee Mac 2010

  (setq dx (lambda ( x l ) (cdr (assoc x l))))

  (if
    (setq lst
      (cond
        (
          (eq "TEXT" (dx 0 (setq l (entget ent))))

          (setq base (dx 10 l) rotn (dx 50 l))

          (
            (lambda ( data )
              (mapcar
                (function
                  (lambda ( funcs )
                    (mapcar
                      (function
                        (lambda ( func )
                          ((eval (car func)) ((eval (cdr func)) data) off)
                        )
                      )
                      funcs
                    )
                  )
                )
                (list
                  (list (cons '- 'caar ) (cons '- 'cadar ))
                  (list (cons '+ 'caadr) (cons '- 'cadar ))
                  (list (cons '+ 'caadr) (cons '+ 'cadadr))
                  (list (cons '- 'caar ) (cons '+ 'cadadr))
                )
              )
            )
            (textbox l)
          )
        )
        (
          (eq "MTEXT" (dx 0 l))

          (setq norm (dx 210 l) base (trans (dx 10 l) 0 norm)
       
                rotn (angle '(0. 0. 0.) (trans (dx 11 l) 0 norm))

                w (dx 42 l) h (dx 43 l)
          )
          (
            (lambda ( org )
              (mapcar
                (function
                  (lambda ( o ) (mapcar '+ org o))
                )
                (list
                  (list (-   off) (-   off))
                  (list (+ w off) (-   off))
                  (list (+ w off) (+ h off))
                  (list (-   off) (+ h off))
                )
              )
            )
            (
              (lambda ( j )
                (list
                  (cond
                    (
                      (member j '(2 5 8)) (/ w -2.)
                    )
                    (
                      (member j '(3 6 9)) (- w)
                    )
                    ( 0. )
                  )
                  (cond
                    (
                      (member j '(1 2 3)) (- h)
                    )
                    (
                      (member j '(4 5 6)) (/ h -2.)
                    )
                    ( 0. )
                  )
                )
             )
             (dx 71 l)
           )
         )
       )
     )
   )
    (progn
      (setq matrix
         (list
           (list (cos rotn) (sin (- rotn)) 0.)
           (list (sin rotn) (cos    rotn)  0.)
           (list     0.           0.       1.)
         )
      )

      (mapcar
        (function
          (lambda ( point )
            (mapcar '+
              (mapcar
                (function
                  (lambda ( r ) (apply '+ (mapcar '* r point)))
                )
                matrix
              )
              (reverse (cdr (reverse base)))
            )
          )
        )
        lst
      )
    )
  )
)

[LISP-LEEMAC] 자동 블럭영역 절단 (포스트아이디 : 7663989620737116235)

;; 출 처 : http://www.lee-mac.com/autoblockbreak.html
;; 제 목 : Automatic Block Break
;; 버 전 : V1.4
;; 명령어 : ABB / ABBE / ABBS
 ;;AutoBlockBreak.gif
 ;;AutoBlockBreakE.gif


;;----------------=={ Automatic Block Break }==---------------;;
;;                                                            ;;
;;  Prompts user for selection of a block, then point for     ;;
;;  insertion.                                                ;;
;;                                                            ;;
;;  If a curve is detected at the selected point, the         ;;
;;  inserted block is rotated to align with the curve.        ;;
;;                                                            ;;
;;  All surrounding objects found to intersect with the block ;;
;;  are then trimmed to the rectangular block outline.        ;;
;;                                                            ;;
;;  Program works in all views & UCS.                         ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright ?2011 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;  Version 1.0    -    22.11.2010                            ;;
;;                                                            ;;
;;  First Release.                                            ;;
;;------------------------------------------------------------;;
;;  Version 1.1    -    07.02.2011                            ;;
;;                                                            ;;
;;  Entire program rewritten to allow subfunction to be       ;;
;;  called with block object argument.                        ;;
;;  Multiple intersecting objects are trimmed.                ;;
;;------------------------------------------------------------;;
;;  Version 1.2    -    08.02.2011                            ;;
;;                                                            ;;
;;  Changed block insertion to VL InsertBlock method.         ;;
;;  Added calling function to trim a block in-situ (ABBE).    ;;
;;------------------------------------------------------------;;
;;  Version 1.3    -    03.08.2011                            ;;
;;                                                            ;;
;;  Altered method to create bounding polyline to exclude     ;;
;;  attributes when trimming objects surrounding block.       ;;
;;  Objects surrounding blocks whose insertion point does not ;;
;;  lie on a curve are now also trimmed.                      ;;
;;------------------------------------------------------------;;
;;  Version 1.4    -    30.09.2011                            ;;
;;                                                            ;;
;;  Added option to enable/disable automatic block rotation.  ;;
;;  Updated code formatting.                                  ;;
;;------------------------------------------------------------;;

(defun c:ABB ( / *error* _StartUndo _EndUndo acspc block obj pt sel )

    (defun *error* ( msg )
        (if acdoc (_EndUndo acdoc))
        (if (not (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*"))
            (princ (strcat "\nError: " msg))
        )
        (princ)
    )

    (defun _StartUndo ( doc )
        (_EndUndo doc)
        (vla-StartUndoMark doc)
    )

    (defun _EndUndo ( doc )
        (if (= 8 (logand 8 (getvar 'UNDOCTL)))
            (vla-EndUndoMark doc)
        )
    )

    (setq acdoc (cond (acdoc) ((vla-get-activedocument (vlax-get-acad-object))))
          acspc (vlax-get-property acdoc (if (= 1 (getvar 'CVPORT)) 'paperspace 'modelspace))
    )
    (if
        (and
            (progn
                (while
                    (progn (setvar 'ERRNO 0) (initget "Browse Rotation")
                        (princ (strcat "\nAutomatic Block Rotation: " (getenv "LMac\\ABBRotation")))
                        (setq sel
                            (entsel
                                (strcat "\nSelect Block [Browse/Rotation]"
                                    (if (eq "" (setq block (getvar 'INSNAME))) ": " (strcat " <" block "> : "))
                                )
                            )
                        )
                        (cond
                            (   (= 7 (getvar 'ERRNO))
                                (princ "\nMissed, Try Again.")
                            )
                            (   (not sel)
                                (if (eq "" block) (setq block nil))
                            )
                            (   (eq "Rotation" sel)
                                (initget "ON OFF")
                                (setenv "LMac\\ABBRotation"
                                    (cond
                                        (
                                            (getkword
                                                (strcat "\nAutomatic Block Rotation [ON/OFF] <"
                                                    (getenv "LMac\\ABBRotation") ">: "
                                                )
                                            )
                                        )
                                        (   (getenv "LMac\\ABBRotation")   )
                                    )
                                )
                            )
                            (   (eq "Browse" sel)
                                (setq block (getfiled "Select Block" "" "dwg" 16))
                                nil
                            )
                            (   (listp sel)
                                (if (not (eq "INSERT" (cdr (assoc 0 (entget (car sel))))))
                                    (princ "\nObject Must be a Block.")
                                    (not (setq obj (vla-copy (vlax-ename->vla-object (car sel)))))
                                )
                            )
                        )
                    )
                )
                block
            )
            (setq pt (getpoint "\nSpecify Point for Block: "))
            (or obj
                (setq obj
                    (vla-InsertBlock acspc (vlax-3D-point (trans pt 1 0)) block 1. 1. 1.
                        (angle '(0. 0. 0.) (trans (getvar 'UCSXDIR) 0 (trans '(0. 0. 1.) 1 0 t) t))
                    )
                )
            )
        )
        (progn
            (_StartUndo acdoc)
            (if block (setvar 'INSNAME (vl-filename-base block)))
            (vla-put-InsertionPoint obj (vlax-3D-point (trans pt 1 0)))
            (LM:AutoBlockBreak obj (eq "ON" (getenv "LMac\\ABBRotation")))
            (_EndUndo acdoc)
        )
    )
    (princ)
)

;;------------=={ Automatic Block Break Existing }==----------;;
;;                                                            ;;
;;  Prompts user for selection of a block and, if a curve is  ;;
;;  detected at the block insertion point, the block is       ;;
;;  rotated to align with the curve. All objects found to     ;;
;;  intersect with the block are then trimmed to the          ;;
;;  rectangular block outline.                                ;;
;;                                                            ;;
;;  Program works in all views & UCS.                         ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright ?2011 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;

(defun c:ABBE ( / sel )
    (while
        (progn
            (setvar 'ERRNO 0)
            (initget "Rotation")
            (princ (strcat "\nAutomatic Block Rotation: " (getenv "LMac\\ABBRotation")))
            (setq sel (entsel "\nSelect Block to Trim [Rotation]: "))
            (cond
                (   (= 7 (getvar 'ERRNO))
                    (princ "\nMissed, Try Again.")
                )
                (   (eq "Rotation" sel)
                    (initget "ON OFF")
                    (setenv "LMac\\ABBRotation"
                        (cond
                            (
                                (getkword
                                    (strcat "\nAutomatic Block Rotation [ON/OFF] <"
                                        (getenv "LMac\\ABBRotation") ">: "
                                    )
                                )
                            )
                            (   (getenv "LMac\\ABBRotation")   )
                        )
                    )
                )
                (   (eq 'ENAME (type (car sel)))
                    (if (eq "INSERT" (cdr (assoc 0 (entget (car sel)))))
                        (LM:AutoBlockBreak (car sel) (eq "ON" (getenv "LMac\\ABBRotation")))
                        (princ "\nInvalid Object Selected.")
                    )
                    t
                )
            )
        )
    )
    (princ)
)

;;-----------=={ Automatic Block Break Selection }==----------;;
;;                                                            ;;
;;  Prompts user for selection of a set of blocks and, if a   ;;
;;  curve is detected at each block insertion point, the      ;;
;;  block is rotated to align with the curve. All objects     ;;
;;  found to intersect with the block are then trimmed to the ;;
;;  rectangular block outline.                                ;;
;;                                                            ;;
;;  Program works in all views & UCS.                         ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright ?2011 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;

(defun c:ABBS ( / ss i )
    (if (setq ss (ssget "_:L" '((0 . "INSERT"))))
        (repeat (setq i (sslength ss))
            (LM:AutoBlockBreak (ssname ss (setq i (1- i))) (eq "ON" (getenv "LMac\\ABBRotation")))
        )
    )
    (princ)
)

;;----------=={ Automatic Block Break SubFunction }==---------;;
;;                                                            ;;
;;  Takes a block reference argument and trims surrounding    ;;
;;  geometry if curve is detected at the insertion point of   ;;
;;  the block.                                                ;;
;;                                                            ;;
;;  If a curve is detected, the block is rotated to align     ;;
;;  with the curve and all  objects found to intersect with   ;;
;;  the block are trimmed to the rectangular block outline.   ;;
;;                                                            ;;
;;  Program works in all views & UCS.                         ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright ?2011 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  block - EName or VLA-Object of Block Reference object     ;;
;;------------------------------------------------------------;;

(defun LM:AutoBlockBreak

    ( block rotate / *error* _GetFurthestApart acspc bbx brk cmd crv en ent enx int lst mat nme ply pt ss x )

    (defun *error* ( msg )
        (if (and ply (not (vlax-erased-p ply))) (vla-delete ply))
        (if cmd  (setvar 'CMDECHO cmd))
        (if (not (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*"))
            (princ (strcat "\nError: " msg))
        )
        (princ)
    )

    (defun _GetFurthestApart ( lst / mx p1 p2 ds rslt )
        (setq mx 0.0)
        (while (setq p1 (car lst))
            (foreach p2 (setq lst (cdr lst))
                (if (< mx (setq ds (distance p1 p2))) (setq mx ds rslt (list p1 p2)))
            )
        )
        rslt
    )

    (setq cmd (getvar 'CMDECHO))
    (setvar 'CMDECHO 0)

    (setq acdoc (cond (acdoc) ((vla-get-activedocument (vlax-get-acad-object))))
          acblk (cond (acblk) ((vla-get-blocks acdoc)))
          acspc (vlax-get-property acdoc (if (= 1 (getvar 'CVPORT)) 'paperspace 'modelspace))
    )

    (if
        (and
            (setq ent
                (cond
                    (   (eq 'ENAME (type block))
                        block
                    )
                    (   (eq 'VLA-OBJECT (type block))
                        (vlax-vla-object->ename block)
                    )
                )
            )
            (setq enx (entget ent))
            (eq "INSERT" (cdr (assoc 0 enx)))
        )
        (progn
            (if rotate
                (progn
                    (setq pt (cdr (assoc 10 enx)))
                    (if
                        (setq ss
                            (ssget "_C"
                                (polar (trans pt ent 1) (/       pi -4.) 1e-4)
                                (polar (trans pt ent 1) (/ (* 3. pi) 4.) 1e-4)
                               '((0 . "~INSERT,ARC,ELLIPSE,CIRCLE,*LINE"))
                            )
                        )
                        (progn (setq crv (ssname ss 0))
                            (entupd
                                (cdr
                                    (assoc -1
                                        (entmod
                                            (subst
                                                (cons 50
                                                    (LM:MakeReadable
                                                        (angle '(0. 0. 0.)
                                                            (trans
                                                                (vlax-curve-getFirstDeriv crv
                                                                    (vlax-curve-getParamatPoint crv
                                                                        (vlax-curve-getClosestPointto crv (trans pt ent 0))
                                                                    )
                                                                )
                                                                0 crv
                                                            )
                                                        )
                                                    )
                                                )
                                                (assoc 50 enx) enx
                                            )
                                        )
                                    )
                                )
                            )
                        )
                    )
                )
            )
            (setq nme (cdr (assoc 2 enx))
                  mat (RefGeom ent)
            )
            (setq bbx
                (mapcar '(lambda ( x ) (mapcar '+ (mxv (car mat) x) (cadr mat)))
                    (cond
                        (   (cdr (assoc nme *blockboundingboxes*))   )
                        (   (cdar
                                (setq *blockboundingboxes*
                                    (cons
                                        (cons nme (LM:BlockDefinitionBoundingBox acblk nme)) *blockboundingboxes*
                                    )
                                )
                            )
                        )
                    )
                )
            )
            (if
                (setq ss
                    (ssget "_C"
                        (trans (car   bbx) 0 1)
                        (trans (caddr bbx) 0 1)
                       '((0 . "~INSERT,ARC,ELLIPSE,CIRCLE,*LINE"))
                    )
                )
                (progn
                    (vla-put-closed (setq ply (vlax-invoke acspc 'add3dpoly (apply 'append bbx))) :vlax-true)
                    (while (setq en (ssname ss 0))
                        (if (setq int (LM:GroupByNum (vlax-invoke (vlax-ename->vla-object en) 'IntersectWith ply acExtendThisEntity) 3))
                            (setq lst (cons (cons en int) lst))
                        )
                        (ssdel en ss)
                    )
                    (vla-delete ply)
                    (foreach int lst
                        (setq brk (_GetFurthestApart (cdr int)))
                        (command
                            "_.break" (list  (car int) (trans (car brk) 0 1)) "_F"
                               "_non" (trans (car  brk) 0 1)
                               "_non" (trans (cadr brk) 0 1)
                        )
                    )
                )
            )
        )
    )
    (setvar 'CMDECHO cmd)
    (princ)
)

;;-------------=={ Block Definition BoundingBox }==-----------;;
;;                                                            ;;
;;  Returns a point list describing a rectangular frame       ;;
;;  bounding all objects in a block definition.               ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright ?2011 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  blocks - The Block Collection in which the block resides  ;;
;;  block  - The name of the block                            ;;
;;------------------------------------------------------------;;
;;  Returns: Point list describing boundingbox of definition  ;;
;;------------------------------------------------------------;;

(defun LM:BlockDefinitionBoundingBox ( blocks block / l1 l2 ll ur )
    (vlax-for obj (vla-item blocks block)
        (if
            (and
                (vlax-method-applicable-p obj 'getboundingbox)
                (not (eq "AcDbAttributeDefinition" (vla-get-objectname obj)))
            )
            (if
                (not
                    (vl-catch-all-error-p
                        (vl-catch-all-apply 'vla-getboundingbox (list obj 'll 'ur))
                    )
                )
                (setq l1 (cons (vlax-safearray->list ll) l1)
                      l2 (cons (vlax-safearray->list ur) l2)
                )
            )
        )
    )
    (if l1
        (
            (lambda ( boundingbox )
                (mapcar
                    (function
                        (lambda ( _functionlist )
                            (mapcar
                                (function
                                    (lambda ( _function ) ((eval _function) boundingbox))
                                )
                                _functionlist
                            )
                        )
                    )
                   '((caar cadar) (caadr cadar) (caadr cadadr) (caar cadadr))
                )
            )
            (list
                (apply 'mapcar (cons 'min l1))
                (apply 'mapcar (cons 'max l2))
            )
        )
    )
)

;; RefGeom (gile)
;; Returns a list which first item is a 3x3 transformation matrix (rotation,
;; scales, normal) and second item the object insertion point in its parent
;; (xref, block or space)
;;
;; Argument : an ename

(defun RefGeom ( ename / elst ang norm mat )
    (setq elst (entget ename)
          ang  (cdr (assoc 50 elst))
          norm (cdr (assoc 210 elst))
    )
    (list
        (setq mat
            (mxm
                (mapcar '(lambda ( v ) (trans v 0 norm T))
                   '(
                        (1.0 0.0 0.0)
                        (0.0 1.0 0.0)
                        (0.0 0.0 1.0)
                    )
                )
                (mxm
                    (list
                        (list (cos ang) (- (sin ang)) 0.0)
                        (list (sin ang) (cos ang)     0.0)
                        (list    0.0       0.0        1.0)
                    )
                    (list
                        (list (cdr (assoc 41 elst)) 0.0 0.0)
                        (list 0.0 (cdr (assoc 42 elst)) 0.0)
                        (list 0.0 0.0 (cdr (assoc 43 elst)))
                    )
                )
            )
        )
        (mapcar '- (trans (cdr (assoc 10 elst)) norm 0)
            (mxv mat (cdr (assoc 10 (tblsearch "BLOCK" (cdr (assoc 2 elst))))))
        )
    )
)

;; Matrix x Vector - Vladimir Nesterovsky
;; Args: m - nxn matrix, v - vector in R^n

(defun mxv ( m v ) (mapcar '(lambda ( r ) (apply '+ (mapcar '* r v))) m))

;; Matrix Transpose - Doug Wilson
;; Args: m - nxn matrix

(defun trp ( m ) (apply 'mapcar (cons 'list m)))

;; Matrix x Matrix - Vladimir Nesterovsky
;; Args: m,n - nxn matrices

(defun mxm ( m n ) ( (lambda ( a ) (mapcar '(lambda ( r ) (mxv a r)) m)) (trp n)))

;;-----------------=={ Group by Number }==--------------------;;
;;                                                            ;;
;;  Groups a list into a list of lists, each of length 'n'    ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright ?2011 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  l - List to process                                       ;;
;;  n - Number of elements by which to group the list         ;;
;;------------------------------------------------------------;;
;;  Returns:  List of lists, each of length 'n'               ;;
;;------------------------------------------------------------;;

(defun LM:GroupByNum ( l n / r)
    (if l
        (cons
            (reverse (repeat n (setq r (cons (car l) r) l (cdr l)) r))
            (LM:GroupByNum l n)
        )
    )
)

;;-------------------=={ Make Readable }==--------------------;;
;;                                                            ;;
;;  Returns an angle corrected for text readability           ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright ?2011 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  a - angle to process                                      ;;
;;------------------------------------------------------------;;
;;  Returns:  angle corrected for text readability            ;;
;;------------------------------------------------------------;;

(defun LM:MakeReadable ( a )
    (   (lambda ( a ) (if (and (< (/ pi 2.0) a) (<= a (/ (* 3.0 pi) 2.0))) (+ a pi) a))
        (rem (+ a pi pi) (+ pi pi))
    )
)

;;------------------------------------------------------------;;

(if (null (getenv "LMac\\ABBRotation"))
    (setenv "LMac\\ABBRotation" "ON")
)

;;------------------------------------------------------------;;

(vl-load-com) (princ)
(princ "\n:: AutoBlockBreak.lsp | Version 1.4 | ?Lee Mac 2011 www.lee-mac.com ::")
(princ "\n:: Type \"ABB\" to insert & break or \"ABBE\"/\"ABBS\" to break existing ::")
(princ)

;;------------------------------------------------------------;;
;;                        End of File                         ;;
;;------------------------------------------------------------;;

[LISP-LEEMAC] 속성객체 색상설정 (포스트아이디 : 8060868850830702893)

;; 출 처 : http://www.lee-mac.com/attributecolour.html
;; 제 목 : Attribute Colour
;; 버 전 : V1.0
;; 명령어 : AttCol
 ;;AttributeColour.png


;;-------------------=={ Attribute Colour }==-----------------;;
;;                                                            ;;
;;  Prompts for a selection of attributed blocks and displays ;;
;;  a dialog interface enabling the user to change the colour ;;
;;  of specific attribute tags.                               ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright ?2011 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;  Version 1.0    -    24-02-2011                            ;;
;;                                                            ;;
;;  First Release.                                            ;;
;;------------------------------------------------------------;;

(defun c:AttCol ( / *error* _StartUndo _EndUndo _unique _dclsel _dclimg doc l s ss ) (vl-load-com)
  ;; ?Lee Mac 2011

  (or *attcolour* (setq *attcolour* 1)) ;; First time default colour

  (defun *error* ( msg )
    (if doc (_EndUndo doc))
    (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
        (princ (strcat "\n** Error: " msg " **")))
    (princ)
  )

  (defun _StartUndo ( doc ) (_EndUndo doc)
    (vla-StartUndoMark doc)
  )

  (defun _EndUndo ( doc )
    (if (= 8 (logand 8 (getvar 'UNDOCTL)))
      (vla-EndUndoMark doc)
    )
  )

  (defun _unique ( l ) (if l (cons (car l) (_unique (vl-remove (car l) (cdr l))))))

  (defun _dclsel ( l / file tmp dch return )
    (cond
      (
        (not
          (and (setq file (open (setq tmp (vl-filename-mktemp nil nil ".dcl")) "w"))
            (write-line
              (strcat
                "attcol : dialog { label = \"Attribute Colour\"; spacer;"
                "  : list_box { label = \"Select Tags\"; key = \"tags\"; fixed_width = false; multiple_select = true ; alignment = centered; }"
                "  : boxed_column { label = \"Colour\";"
                "    : row { spacer;"
                "      : button { key = \"but\"; width = 12; fixed_width = true; label = \"Select Colour\"; }"
                "      : image_button { key = \"img\"; alignment = centered; height = 1.5; width = 4.0;"
                "                       fixed_width = true; fixed_height = true; color = 2; }"
                "      spacer;"
                "    }"
                "    spacer;"
                "  }"
                "  spacer; ok_cancel;"
                "}"
              )
              file
            )
            (not (close file)) (< 0 (setq dch (load_dialog tmp))) (new_dialog "attcol" dch)
          )
        )
      )
      (t
        (start_list "tags") (mapcar 'add_list l) (end_list)

        (setq return (set_tile "tags" "0"))
        (_dclimg "img" *attcolour*)

        (action_tile "img"  "(_dclimg \"img\" (setq *attcolour* (cond ( (acad_colordlg *attcolour*) ) ( *attcolour* ))))")
        (action_tile "but"  "(_dclimg \"img\" (setq *attcolour* (cond ( (acad_colordlg *attcolour*) ) ( *attcolour* ))))")
        (action_tile "tags" "(setq return $value)")

        (setq return
          (if (= 1 (start_dialog))
            (mapcar '(lambda ( x ) (nth x l)) (read (strcat "(" return ")")))
          )
        )
      )
    )

    (if (< 0 dch) (unload_dialog dch))
    (if (setq tmp (findfile tmp)) (vl-file-delete tmp))

    return
  )

  (defun _dclimg ( k c )
    (start_image k) (fill_image 0 0 (dimx_tile k) (dimy_tile k) c) (end_image)
  )

  (setq doc (vla-get-ActiveDocument (vlax-get-acad-object)))

  (if
    (and (ssget "_:L" '((0 . "INSERT") (66 . 1)))
      (progn
        (vlax-for obj (setq ss (vla-get-ActiveSelectionSet doc))        
          (foreach att
            (append (vlax-invoke obj 'GetAttributes) (vlax-invoke obj 'GetConstantAttributes))
            (setq l (cons (cons (vla-get-TagString att) att) l))
          )
        )
        (vla-delete ss)
        (setq s (_dclsel (acad_strlsort (_unique (mapcar 'car l)))))
      )
    )
    (progn
      (_StartUndo doc)
      (foreach pair l (if (vl-position (car pair) s) (vla-put-color (cdr pair) *attcolour*)))
      (_EndUndo doc)
    )
    (princ "\n*Cancel*")
  )

  (princ)
)

(princ)
(princ "\n:: AttributeColour.lsp | Version 1.0 | ?Lee Mac 2011 www.lee-mac.com ::")
(princ "\n:: Type \"AttCol\" to Invoke ::")
(princ)

;;------------------------------------------------------------;;
;;                         End of File                        ;;
;;------------------------------------------------------------;;

[LISP-LEEMAC] 결합된 원과 센터라인 (포스트아이디 : 1571976847866424376)

;; 출 처 : http://www.lee-mac.com/associativecenterlines.html
;; 제 목 : Associative Centerlines
;; 버 전 : V1.0
;; 명령어 : CL / CLRemove
 ;;AreaLabelV1-5.gif


;;--------------=={ Associative Centerlines }==---------------;;
;;                                                            ;;
;;  Uses reactors to update centerlines following             ;;
;;  modification of associated circles. Stores entity handles ;;
;;  in entity xData to enable reactor rebuild upon loading,   ;;
;;  allowing retention of associativity between sessions.     ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright ?2011 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;  Version 1.0    -    12-05-2011                            ;;
;;------------------------------------------------------------;;

(setq cl:ratio 1.25 cl:app "LMAC_CL")

;;------------------------------------------------------------;;

(defun c:cl ( / _line ss e c r l1 l2 )
  (if
    (and
      (setq ss
        (ssget
          (list '(0 . "CIRCLE") '(-4 . "<NOT") (list -3 (list cl:app)) '(-4 . "NOT>"))
        )
      )
      (or (tblsearch "APPID" cl:app) (regapp cl:app))
    )
    (progn
      (defun _line ( p1 p2 h )
        (entmakex
          (list (cons 0 "LINE") (cons 10 p1) (cons 11 p2)
            (list -3
              (list cl:app
                (cons 1002 "{") (cons 1005 h) (cons 1002 "}")
              )
            )
          )
        )
      )
      (repeat (setq i (sslength ss))
        (setq e  (entget (ssname ss (setq i (1- i))))
              h  (cdr (assoc  5 e))
              c  (cdr (assoc 10 e))
              r  (* cl:ratio (cdr (assoc 40 e)))
              l1 (_line (polar c 0. r) (polar c pi r) h)
              l2 (_line (polar c (/ pi 2.) r) (polar c (/ (* 3. pi) 2.) r) h)
        )
        (entmod
          (list (assoc -1 e)
            (list -3
              (list cl:app
                (cons 1002 "{")
                (cons 1005 (cdr (assoc 5 (entget l1))))
                (cons 1005 (cdr (assoc 5 (entget l2))))
                (cons 1002 "}")
              )
            )
          )
        )
        (vlr-object-reactor (list (vlax-ename->vla-object (cdr (assoc -1 e)))) (list cl:app h)
          (list
            (cons :vlr-modified 'cl:circle:callback)
          )
        )
        (vlr-object-reactor (mapcar 'vlax-ename->vla-object (list l1 l2)) (list cl:app h)
          (list
            (cons :vlr-modified 'cl:line:callback)
          )
        )
      )
    )
  )
  (princ)
)

;;------------------------------------------------------------;;

(defun c:clremove ( / _massoc ss fl i e r d h x )

  (defun _massoc ( x l )
    (if (setq a (assoc x l))
      (cons (cdr a) (_massoc x (cdr (member a l))))
    )
  )

  (princ "\nSelect Circles to Remove Associativity <All>: ")
  (setq fl (list '(0 . "CIRCLE") (list -3 (list cl:app))) i -1)

  (if
    (setq ss
      (cond
        ( (ssget fl) )
        ( (ssget "_X" fl) )
      )
    )
    (while (setq e (ssname ss (setq i (1+ i)))) (setq e (entget e (list cl:app)))
      (foreach r (cdar (vlr-reactors :vlr-object-reactor))
        (if
          (and
            (setq d (vlr-data r))
            (listp d)
            (eq cl:app (car d))
            (or (not (cadr d)) (eq (cdr (assoc 5 e)) (cadr d)))
          )
          (vlr-remove r)
        )
      )
      (foreach h (_massoc 1005 (cdadr (assoc -3 e)))
        (if (setq x (entget (handent h)))
          (entmod (list (assoc -1 x) (list -3 (list cl:app))))
        )
      )
      (entmod (list (assoc -1 e) (list -3 (list cl:app))))
    )
  )
  (princ)
)    

;;------------------------------------------------------------;;

(defun cl:circle:callback ( owner reactor params / xtyp xval c r )
  (if
    (and
      (vlax-read-enabled-p owner)
      (progn (vla-getxdata owner cl:app 'xtyp 'xval) xval)
      (setq
        c (vlax-get owner 'center)
        r (* cl:ratio (vlax-get owner 'radius))
      )
    )
    (mapcar
      (function
        (lambda ( h a )
          (if (or (entget (setq h (handent h))) (entdel h))
            (entmod
              (list (cons -1 h) (cons 10 (polar c a r)) (cons 11 (polar c (+ a pi) r)))
            )
          )
        )
      )
      (cddr (mapcar 'vlax-variant-value (vlax-safearray->list xval))) (list 0. (/ pi 2.))
    )
  )
  (princ)
)

;;------------------------------------------------------------;;

(defun cl:line:callback ( owner reactor params )
  (setq *data (list owner reactor))
  (vlr-command-reactor (list cl:app)
    (list
      (cons :vlr-commandended     'cl:line:modify)
      (cons :vlr-commandcancelled 'cl:line:cancelled)
      (cons :vlr-commandfailed    'cl:line:cancelled)
    )
  )
  (vlr-remove reactor)
  (princ)
)

;;------------------------------------------------------------;;

(defun cl:line:modify ( reactor params / xtyp xval h ) (vlr-remove reactor)
  (if
    (and *data (not (vlax-erased-p (car *data))) (progn (vla-getxdata (car *data) cl:app 'xtyp 'xval) xval)  
      (or
        (entget
          (setq h
            (handent
              (caddr
                (mapcar 'vlax-variant-value (vlax-safearray->list xval))
              )
            )
          )
        )
        (entdel h)
      )
    )
    (progn
      (cl:circle:callback (vlax-ename->vla-object h) nil nil)
      (vlr-add (cadr *data))
      (setq *data nil)
    )
  )
  (princ)
)

;;------------------------------------------------------------;;

(defun cl:line:cancelled ( reactor params ) (vlr-remove reactor)
  (if *data
    (progn
      (vlr-add (cadr *data))
      (setq *data nil)
    )
  )
  (princ)
)

;;------------------------------------------------------------;;

(
  (lambda ( / r d s i e o xtyp xval )
    (foreach r (cdar (vlr-reactors :vlr-object-reactor))
      (if (and (setq d (vlr-data r)) (listp d) (eq cl:app (car d)))
        (vlr-remove r)
      )
    )
    (if (setq s (ssget "_X" (list '(0 . "CIRCLE") (list -3 (list cl:app)))))
      (repeat (setq i (sslength s))
        (setq e (ssname s (setq i (1- i))))
        (vlr-object-reactor (list (setq o (vlax-ename->vla-object e))) (list cl:app (cdr (assoc 5 (entget e))))
          (list
            (cons :vlr-modified 'cl:circle:callback)
          )
        )
        (vla-getxdata o cl:app 'xtyp 'xval) (setq xval (mapcar 'vlax-variant-value (vlax-safearray->list xval)))
        (vlr-object-reactor
          (mapcar
            (function
              (lambda ( h )
                (or (entget (setq h (handent h))) (entdel h)) (vlax-ename->vla-object h)
              )
            )
            (list (caddr xval) (cadddr xval))
          )
          (list cl:app (cdr (assoc 5 (entget e)))) (list (cons :vlr-modified 'cl:line:callback))
        )
      )
    )
  )
)

(vl-load-com) (princ)

;;------------------------------------------------------------;;
;;                         End of File                        ;;
;;------------------------------------------------------------;;

[LISP-LEEMAC] 면적라벨 (포스트아이디 : 6937204147639811255)

;; 출 처 : http://www.lee-mac.com/arealabel.html
;; 제 목 : Area Label
;; 버 전 : V1.9 ;;
AreaLabelV1-5.gif
;;명령어 : AT (Table) / AF (File)


;;---------------------=={ Area Label }==---------------------;;
;;                                                            ;;
;;  Allows the user to label picked areas or objects and      ;;
;;  either display the area in an ACAD Table (if available),  ;;
;;  optionally using fields to link area numbers and objects; ;;
;;  or write it to file.                                      ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright ?2011 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;  Version 1.9    -    29-10-2011                            ;;
;;------------------------------------------------------------;;

(defun c:AT nil (AreaLabel   t))  ;; Areas to Table
(defun c:AF nil (AreaLabel nil))  ;; Areas to File

;;------------------------------------------------------------;;

(defun AreaLabel ( flag / *error* _startundo _endundo _centroid _text _open _select _getobjectid _isannotative
                          acdoc acspc ap ar as cf cm el fd fl fo n of om p1 pf pt sf st t1 t2 tb th ts tx ucsxang ucszdir )

  ;;------------------------------------------------------------;;
  ;;                         Adjustments                        ;;
  ;;------------------------------------------------------------;;

  (setq h1 "Area Table"  ;; Heading
        t1 "Number"      ;; Number Title
        t2 "Area"        ;; Area Title
        pf ""            ;; Number Prefix (optional, "" if none)
        sf ""            ;; Number Suffix (optional, "" if none)
        ap ""            ;; Area Prefix (optional, "" if none)
        as ""            ;; Area Suffix (optional, "" if none)
        cf 1.0           ;; Area Conversion Factor (e.g. 1e-6 = mm2->m2)
        fd t             ;; Use fields to link numbers/objects to table (t=yes, nil=no)
        fo "%lu6%qf1"    ;; Area field formatting
  )

  ;;------------------------------------------------------------;;

  (defun *error* ( msg )
    (if cm (setvar 'CMDECHO cm))
    (if el (progn (entdel el) (setq el nil)))
    (if acdoc (_EndUndo acdoc))
    (if (and of (eq 'FILE (type of))) (close of))
    (if (and Shell (not (vlax-object-released-p Shell))) (vlax-release-object Shell))
    (if (null (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*"))
        (princ (strcat "\n--> Error: " msg))
    )
    (princ)
  )

  ;;------------------------------------------------------------;;

  (defun _StartUndo ( doc ) (_EndUndo doc)
    (vla-StartUndoMark doc)
  )

  ;;------------------------------------------------------------;;

  (defun _EndUndo ( doc )
    (if (= 8 (logand 8 (getvar 'UNDOCTL)))
      (vla-EndUndoMark doc)
    )
  )

  ;;------------------------------------------------------------;;

  (defun _centroid ( space objs / reg cen )
    (setq reg (car (vlax-invoke space 'addregion objs))
          cen (vlax-get reg 'centroid)
    )
    (vla-delete reg) (trans cen 1 0)
  )

  ;;------------------------------------------------------------;;

  (defun _text ( space point string height rotation / text )
    (setq text (vla-addtext space string (vlax-3D-point point) height))
    (vla-put-alignment text acalignmentmiddlecenter)
    (vla-put-textalignmentpoint text (vlax-3D-point point))
    (vla-put-rotation text rotation)
    text
  )

  ;;------------------------------------------------------------;;

  (defun _Open ( target / Shell result )
    (if (setq Shell (vla-getInterfaceObject (vlax-get-acad-object) "Shell.Application"))
      (progn
        (setq result
          (and (or (eq 'INT (type target)) (setq target (findfile target)))
            (not
              (vl-catch-all-error-p
                (vl-catch-all-apply 'vlax-invoke (list Shell 'Open target))
              )
            )
          )
        )
        (vlax-release-object Shell)
      )
    )
    result
  )

  ;;------------------------------------------------------------;;

  (defun _Select ( msg pred func init / e ) (setq pred (eval pred))
    (while
      (progn (setvar 'ERRNO 0) (apply 'initget init) (setq e (func msg))
        (cond
          ( (= 7 (getvar 'ERRNO))
            (princ "\nMissed, try again.")
          )
          ( (eq 'STR (type e))
            nil
          )          
          ( (vl-consp e)
            (if (and pred (not (pred (setq e (car e)))))
              (princ "\nInvalid Object Selected.")
            )
          )
        )
      )
    )
    e
  )

  ;;------------------------------------------------------------;;

  (defun _GetObjectID ( doc obj )
    (if (vl-string-search "64" (getenv "PROCESSOR_ARCHITECTURE"))
      (vlax-invoke-method (vla-get-Utility doc) 'GetObjectIdString obj :vlax-false)
      (itoa (vla-get-Objectid obj))
    )
  )

  ;;------------------------------------------------------------;;

  (defun _isAnnotative ( style / object annotx )
    (and
      (setq object (tblobjname "STYLE" style))
      (setq annotx (cadr (assoc -3 (entget object '("AcadAnnotative")))))
      (= 1 (cdr (assoc 1070 (reverse annotx))))
    )
  )

  ;;------------------------------------------------------------;;

  (setq acdoc (vla-get-activedocument (vlax-get-acad-object))
        acspc (vlax-get-property acdoc (if (= 1 (getvar 'CVPORT)) 'Paperspace 'Modelspace))

        ucszdir (trans '(0. 0. 1.) 1 0 t)
        ucsxang (angle '(0. 0. 0.) (trans (getvar 'UCSXDIR) 0 ucszdir))
  )
  (_StartUndo acdoc)
  (setq cm (getvar 'CMDECHO))
  (setvar 'CMDECHO 0)
  (setq om (eq "1" (cond ((getenv "LMAC_AreaLabel")) ((setenv "LMAC_AreaLabel" "0")))))

  (setq ts
    (/ (getvar 'TEXTSIZE)
      (if (_isAnnotative (getvar 'TEXTSTYLE))
        (cond ( (getvar 'CANNOSCALEVALUE) ) ( 1.0 )) 1.0
      )
    )
  )

  (cond
    ( (not (vlax-method-applicable-p acspc 'addtable))

      (princ "\n--> Table Objects not Available in this Version.")
    )
    ( (= 4 (logand 4 (cdr (assoc 70 (tblsearch "LAYER" (getvar 'CLAYER))))))

      (princ "\n--> Current Layer Locked.")
    )
    ( (not
        (setq *al:num
          (cond
            (
              (getint
                (strcat "\nSpecify Starting Number <"
                  (itoa (setq *al:num (1+ (cond ( *al:num ) ( 0 ))))) ">: "
                )
              )
            )
            ( *al:num )
          )
        )
      )
    )
    ( flag

      (setq th
        (* 2.
          (if
            (zerop
              (setq th
                (vla-gettextheight
                  (setq st
                    (vla-item
                      (vla-item
                        (vla-get-dictionaries acdoc) "ACAD_TABLESTYLE"
                      )
                      (getvar 'CTABLESTYLE)
                    )
                  )
                  acdatarow
                )
              )
            )
            ts
            (/ th
              (if (_isAnnotative (vla-gettextstyle st acdatarow))
                (cond ( (getvar 'CANNOSCALEVALUE) ) ( 1.0 )) 1.0
              )
            )
          )
        )
      )

      (if
        (cond
          (
            (progn (initget "Add")
              (vl-consp (setq pt (getpoint "\nPick Point for Table <Add to Existing>: ")))
            )
            (setq tb
              (vla-addtable acspc
                (vlax-3D-point (trans pt 1 0)) 2 2 th (* 0.8 th (max (strlen t1) (strlen t2)))
              )
            )
            (vla-put-direction tb (vlax-3D-point (getvar 'UCSXDIR)))
            (vla-settext tb 0 0 h1)
            (vla-settext tb 1 0 t1)
            (vla-settext tb 1 1 t2)
         
            (while
              (progn
                (if om
                  (setq p1
                    (_Select (strcat "\nSelect Object [Pick] <Exit>: ")
                     '(lambda ( x )
                        (and
                          (vlax-property-available-p (vlax-ename->vla-object x) 'area)
                          (not (eq "HATCH" (cdr (assoc 0 (entget x)))))
                          (or (eq "REGION" (cdr (assoc 0 (entget x)))) (vlax-curve-isclosed x))
                        )
                      )
                      entsel '("Pick")
                    )
                  )
                  (progn (initget "Object") (setq p1 (getpoint "\nPick Area [Object] <Exit>: ")))
                )
                (cond
                  ( (null p1)

                    (vla-delete tb)
                  )
                  ( (eq "Pick" p1)

                    (setq om nil) t
                  )
                  ( (eq "Object" p1)

                    (setq om t)
                  )
                  ( (eq 'ENAME (type p1))

                    (setq tx
                      (cons
                        (_text acspc
                          (_centroid acspc (list (setq p1 (vlax-ename->vla-object p1))))
                          (strcat pf (itoa *al:num) sf)
                          ts
                          ucsxang
                        )
                        tx
                      )
                    )
                    (vla-insertrows tb (setq n 2) th 1)
                    (vla-settext tb n 1
                      (if fd
                        (strcat "%<\\AcObjProp Object(%<\\_ObjId "
                          (_GetObjectID acdoc p1) ">%).Area \\f \"" fo "\">%"
                        )
                        (strcat ap (rtos (* cf (vla-get-area p1)) 2) as)
                      )
                    )
                    (vla-settext tb n 0
                      (if fd
                        (strcat "%<\\AcObjProp Object(%<\\_ObjId "
                          (_GetObjectID acdoc (car tx)) ">%).TextString>%"
                        )
                        (strcat pf (itoa *al:num) sf)
                      )
                    )
                    nil
                  )                    
                  ( (vl-consp p1)

                    (setq el (entlast))
                    (vl-cmdf "_.-boundary" "_A" "_I" "_N" "" "_O" "_P" "" "_non" p1 "")

                    (if (not (equal el (setq el (entlast))))
                      (progn
                        (setq tx
                          (cons
                            (_text acspc
                              (_centroid acspc (list (vlax-ename->vla-object el)))
                              (strcat pf (itoa *al:num) sf)
                              ts
                              ucsxang
                            )
                            tx
                          )
                        )
                        (vla-insertrows tb (setq n 2) th 1)
                        (vla-settext tb n 1 (strcat ap (rtos (* cf (vlax-curve-getarea el)) 2) as))
                        (vla-settext tb n 0
                          (if fd
                            (strcat "%<\\AcObjProp Object(%<\\_ObjId "
                              (_GetObjectID acdoc (car tx)) ">%).TextString>%"
                            )
                            (strcat pf (itoa *al:num) sf)
                          )
                        )
                        (redraw el 3)
                        nil
                      )
                      (vla-delete tb)
                    )
                  )
                )
              )
            )
            (not (vlax-erased-p tb))
          )
          (
            (and
              (setq tb
                (_Select "\nSelect Table to Add to: "
                 '(lambda ( x ) (eq "ACAD_TABLE" (cdr (assoc 0 (entget x))))) entsel nil
                )
              )
              (< 1 (vla-get-columns (setq tb (vlax-ename->vla-object tb))))
            )
            (setq n (1- (vla-get-rows tb)) *al:num (1- *al:num))
          )
        )
        (progn
          (while
            (if om
              (setq p1
                (_Select (strcat "\nSelect Object [" (if tx "Undo/" "") "Pick] <Exit>: ")
                 '(lambda ( x )
                    (and
                      (vlax-property-available-p (vlax-ename->vla-object x) 'area)
                      (not (eq "HATCH" (cdr (assoc 0 (entget x)))))
                      (or (eq "REGION" (cdr (assoc 0 (entget x)))) (vlax-curve-isclosed x))
                    )
                  )
                  entsel (list (if tx "Undo Pick" "Pick"))
                )
              )
              (progn (initget (if tx "Undo Object" "Object"))
                (setq p1 (getpoint (strcat "\nPick Area [" (if tx "Undo/" "") "Object] <Exit>: ")))
              )
            )
            (cond
              ( (and tx (eq "Undo" p1))

                (if el (progn (entdel el) (setq el nil)))
                (vla-deleterows tb n 1)
                (vla-delete (car tx))
                (setq n (1- n) tx (cdr tx) *al:num (1- *al:num))
              )
              ( (eq "Undo" p1)

                (princ "\n--> Nothing to Undo.")
              )
              ( (eq "Object" p1)

                (if el (progn (entdel el) (setq el nil)))
                (setq om t)
              )
              ( (eq "Pick" p1)

                (setq om nil)
              )
              ( (and om (eq 'ENAME (type p1)))

                (setq tx
                  (cons
                    (_text acspc
                      (_centroid acspc (list (setq p1 (vlax-ename->vla-object p1))))
                      (strcat pf (itoa (setq *al:num (1+ *al:num))) sf)
                      ts
                      ucsxang
                    )
                    tx
                  )
                )
                (vla-insertrows tb (setq n (1+ n)) th 1)
                (vla-settext tb n 1
                  (if fd
                    (strcat "%<\\AcObjProp Object(%<\\_ObjId "
                      (_GetObjectID acdoc p1) ">%).Area \\f \"" fo "\">%"
                    )
                    (strcat ap (rtos (* cf (vla-get-area p1)) 2) as)
                  )
                )
                (vla-settext tb n 0
                  (if fd
                    (strcat "%<\\AcObjProp Object(%<\\_ObjId "
                      (_GetObjectID acdoc (car tx)) ">%).TextString>%"
                    )
                    (strcat pf (itoa *al:num) sf)
                  )
                )
              )            
              ( (vl-consp p1)    

                (if el (progn (entdel el) (setq el nil)))
                (setq el (entlast))
                (vl-cmdf "_.-boundary" "_A" "_I" "_N" "" "_O" "_P" "" "_non" p1 "")

                (if (not (equal el (setq el (entlast))))
                  (progn
                    (setq tx
                      (cons
                        (_text acspc
                          (_centroid acspc (list (vlax-ename->vla-object el)))
                          (strcat pf (itoa (setq *al:num (1+ *al:num))) sf)
                          ts
                          ucsxang
                        )
                        tx
                      )
                    )
                    (vla-insertrows tb (setq n (1+ n)) th 1)
                    (vla-settext tb n 1 (strcat ap (rtos (* cf (vlax-curve-getarea el)) 2) as))
                    (vla-settext tb n 0
                      (if fd
                        (strcat "%<\\AcObjProp Object(%<\\_ObjId "
                          (_GetObjectID acdoc (car tx)) ">%).TextString>%"
                        )
                        (strcat pf (itoa *al:num) sf)
                      )
                    )
                    (redraw el 3)
                  )
                  (princ "\n--> Error Retrieving Area.")
                )
              )
            )
          )
          (if el (progn (entdel el) (setq el nil)))
        )
      )
    )
    (
      (and
        (setq fl (getfiled "Create Output File" (cond ( *file* ) ( "" )) "txt;csv;xls" 1))
        (setq of (open fl "w"))
      )
      (setq *file*  (vl-filename-directory fl)
            de      (cdr (assoc (strcase (vl-filename-extension fl) t) '((".txt" . "\t") (".csv" . ",") (".xls" . "\t"))))
            *al:num (1- *al:num)
      )
      (write-line h1 of)
      (write-line (strcat t1 de t2) of)

      (while
        (if om
          (setq p1
            (_Select (strcat "\nSelect Object [Pick] <Exit>: ")
             '(lambda ( x )
                (and
                  (vlax-property-available-p (vlax-ename->vla-object x) 'area)
                  (not (eq "HATCH" (cdr (assoc 0 (entget x)))))
                  (or (eq "REGION" (cdr (assoc 0 (entget x)))) (vlax-curve-isclosed x))
                )
              )
              entsel '("Pick")
            )
          )
          (progn (initget "Object") (setq p1 (getpoint (strcat "\nPick Area [Object] <Exit>: "))))
        )
        (cond
          ( (eq "Object" p1)

            (if el (progn (entdel el) (setq el nil)))
            (setq om t)
          )
          ( (eq "Pick" p1)

            (setq om nil)
          )
          ( (eq 'ENAME (type p1))

            (_text acspc
              (_centroid acspc (list (setq p1 (vlax-ename->vla-object p1))))
              (strcat pf (itoa (setq *al:num (1+ *al:num))) sf)
              ts
              ucsxang
            )        
            (write-line (strcat pf (itoa *al:num) sf de ap (rtos (* cf (vla-get-area p1)) 2) as) of)
          )
          ( (vl-consp p1)
     
            (if el (progn (entdel el) (setq el nil)))
            (setq el (entlast))
            (vl-cmdf "_.-boundary" "_A" "_I" "_N" "" "_O" "_P" "" "_non" p1 "")

            (if (not (equal el (setq el (entlast))))
              (progn
                (_text acspc
                  (_centroid acspc (list (vlax-ename->vla-object el)))
                  (strcat pf (itoa (setq *al:num (1+ *al:num))) sf)
                  ts
                  ucsxang
                )
                (write-line (strcat pf (itoa *al:num) sf de ap (rtos (* cf (vlax-curve-getarea el)) 2) as) of)
                (redraw el 3)
              )
              (princ "\n--> Error Retrieving Area.")
            )
          )
        )
      )
      (if el (progn (entdel el) (setq el nil)))
      (setq of (close of))
      (_Open (findfile fl))
    )    
  )
  (setenv "LMAC_AreaLabel" (if om "1" "0"))
  (setvar 'CMDECHO cm)
  (_EndUndo acdoc)
  (princ)
)

;;------------------------------------------------------------;;

(vl-load-com)
(princ)
(princ "\n:: AreaLabel.lsp | Version 1.9 | ?Lee Mac 2011 www.lee-mac.com ::")
(princ "\n:: Commands: \"AT\" for ACAD Table, \"AF\" for File ::")
(princ)

;;------------------------------------------------------------;;
;;                         End of File                        ;;
;;------------------------------------------------------------;;