请yedajiang兄指点
(defun c:test (/ lst) (vl-load-com) (if (ssget '((0 . "circle"))) (progn (setq *AcadDocument* (vla-Get-ActiveDocument (vlax-Get-Acad-Object))) (vla-StartUndoMark *AcadDocument*) (if (setq lst (GetLst)) (Display lst) ) (vla-EndUndoMark *AcadDocument*) ) ) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun Display (lst / TextPt i pt Text StrDia Dia) (while (not (setq TextPt (Getpoint "\nPlease Specify a point : ")))) (setq old_cmdecho (getvar "cmdecho") old_osmode (getvar "osmode") ) (setvar "cmdecho" 0) (setvar "osmode" 0) (setq i 0) (foreach en lst (setq pt (vlax-safearray->list (vlax-variant-value (vla-get-center (vlax-ename->vla-object (handent (cadr en))))) ) i (1+ i) Text (strcat "No" (itoa i)) ) (command "text" pt 3.5 0 Text) (setq StrDia "") (foreach hn (cdr en) (setq Dia (vla-Get-Diameter (vlax-ename->vla-object (handent hn))) StrDia (strcat strDia " " (rtos Dia 2 2)) ) ) (setq StrDia (strcat Text " " (rtos (car pt) 2 2) " " (rtos (cadr pt) 2 2) " " strDia)) (setq TextPt (list (car TextPt) (- (cadr TextPt) 6))) (command "text" TextPt 3.5 0 StrDia) ) (setvar "cmdecho" old_cmdecho) (setvar "osmode" old_osmode) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun GetLst (/ ss pt hand lst) (setq ss (vla-Get-ActiveSelectionset *AcadDocument*)) (setq lst '()) (vlax-for en ss (setq pt (vlax-safearray->list (vlax-variant-value (vla-get-center en))) hand (vla-get-handle en) ) (if (assoc pt lst) (setq lst (subst (append (assoc pt lst) (list hand)) (assoc pt lst) lst)) (setq lst (append lst (list (list pt hand)))) ) ) lst ) [/QUOTE] |