根据您的示例图纸。。试试这个:
- (defun c:foo (/ p t1 t2 t3 x y)
- ;; RJP - 07.07.2017
- ;; Load visual lisp
- (vl-load-com)
- ;; This is a the y offset for text based on example drawing
- ;; (setq y 0.145833)
- (cond
- ;; If no text on layer "OLI_IDTEXT" are in the drawing exit and prompt
- ((null (setq t1 (ssget "_x" '((0 . "text") (8 . "OLI_IDTEXT")))))
- (print "'OLI_IDTEXT' text not found!")
- )
- ;; If no text on layer "OLI_ANTEXT" are in the drawing exit and prompt
- ((null (setq t2 (ssget "_x" '((0 . "text") (8 . "OLI_ANTEXT")))))
- (print "'OLI_ANTEXT' text not found!")
- )
- ;; Rock and roll .. compile a list of all the green text to be moved as a list of ((<alignment_point> . ename)...)
- ((setq
- t2 (mapcar '(lambda (x) (cons (cdr (assoc 11 (entget x))) x)) (mapcar 'cadr (ssnamex t2)))
- )
- ;; Changed to be a 2X factor of the text height in drawing
- (setq y (* 2. (cdr (assoc 40 (entget (cdr (car t2)))))))
- ;; Foreach base text
- (foreach base (mapcar 'cadr (ssnamex t1))
- ;; Grab the alignment point to move to
- (setq p (cdr (assoc 11 (entget base))))
- (if
- ;; Sort the 'green text' list by distance
- (and (setq t3 (vl-sort t2 '(lambda (a b) (< (distance p (car a)) (distance p (car b))))))
- ;; and check that we have at least 3 items in the sorted list
- (>= (length t3) 3)
- );; For the first 3 items in sorted green text list ( closest to base text )
- (foreach x (list (car t3) (cadr t3) (caddr t3))
- ;; Move the text using the base text x value and incrementing the y value by 2X the text height
- (vlax-invoke
- (vlax-ename->vla-object (cdr x))
- 'move
- (car x)
- (setq p (list (car p) (+ y (cadr p)) 0.0))
- )
- ;; Remove the item from the 'green text' list so it won't get processed twice
- (setq t2 (vl-remove x t2))
- )
- )
- )
- )
- )
- ;; Shhhh
- (princ)
- )
|