Jump to content

Lisp lệnh TMP trong chủ đề “[yêu cầu] Lips move line; pline; vuông góc với line hay pline có sẵn”

Sửa lại. Không thấy bạn test với text thế nào?

(defun c:tmp()
(defun dxf (id v) (cdr (assoc id (entget v))))
(defun getNear(v ent)
(setq tm (vl-sort (list (vlax-curve-getStartPoint v) (vlax-curve-getEndPoint v))
'(lambda(x y) (< (distance x (vlax-curve-getClosestPointTo ent x))
(distance y (vlax-curve-getClosestPointTo ent y)))))
tm1 (vlax-curve-getClosestPointTo ent (car tm)))
)
 
(defun thgoc (ent pt / param)
(if (setq param (vlax-curve-getParamAtPoint ent pt))
(- (angle '(0 0 0) (vlax-curve-getFirstDeriv ent param)) (/ pi 2))
nil)
)
(defun laydinh(v / n L node)
(setq v (vlax-ename->vla-object v)
n -1 L nil)
(vl-catch-all-error-p (vl-catch-all-apply '(lambda() 
(while (setq node (vla-get-Coordinate v (setq n (1+ n)))) 
(setq L (append L (list (vlax-safearray->list (vlax-variant-value node)))))))))
L
)
 
;;;
(vl-load-com)
(command "undo" "be")
(setq ent (car (entsel "\nChon duong dan:"))
os (getvar 'osmode))
(setvar 'osmode 0)
(prompt "\nChon doi tuong can move:")  
(mapcar '(lambda(x)
(cond ((= "LINE" (dxf 0 x)) (getNear x ent)
(command "move" x "" (car tm) tm1)
(command "rotate" x "" tm1 "r" tm1 (polar tm1 (angle (car tm) (last tm)) 1) (polar tm1 (thgoc ent tm1) 1)))
 
((vl-string-search "LINE" (dxf 0 x)) (getNear x ent) 
(command "move" x "" (car tm) tm1)
(setq tm2 (if (< (distance tm1 (car (setq tm3 (laydinh x)))) 0.1) (nth 1 tm3) (nth (- (length tm3) 2) tm3)))
(command "rotate" x "" tm1 "r" tm1 (polar tm1 (angle tm1 tm2) 1)
(polar tm1 (thgoc ent tm1) 1)))
 
((vl-string-search "TEXT" (dxf 0 x))
(command "move" x "" (dxf 10 x) (setq tm1 (vlax-curve-getClosestPointTo ent (dxf 10 x))))
(command "rotate" x "" tm1 "r" tm1 (polar tm1 (dxf 50 x) 1) (polar tm1 (thgoc ent tm1) 1)))
 
)) (acet-ss-to-list (ssget '((0 . "*LINE,*TEXT"))))
)
(command "undo" "e") (setvar 'osmode os) (princ)
)

Tệp .lsp gốc không còn trên máy chủ. Hãy chép mã nguồn bên dưới (lấy từ bài viết gốc) vào một tệp văn bản, lưu với đuôi .lsp.

Cách dùng

  1. Chép mã nguồn, lưu thành tệp 297915_tmp.lsp.
  2. Trong AutoCAD gõ lệnh APPLOAD, chọn tệp vừa tải rồi bấm Load. Cũng có thể kéo thả tệp .lsp vào cửa sổ bản vẽ.
  3. Gõ lệnh TMP để chạy lisp.

Mã nguồn 297915_tmp.lsp (trích từ bài viết gốc)

(defun c:tmp()
(defun dxf (id v) (cdr (assoc id (entget v))))
(defun getNear(v ent)
(setq tm (vl-sort (list (vlax-curve-getStartPoint v) (vlax-curve-getEndPoint v))
'(lambda(x y) (< (distance x (vlax-curve-getClosestPointTo ent x))
(distance y (vlax-curve-getClosestPointTo ent y)))))
tm1 (vlax-curve-getClosestPointTo ent (car tm)))
)
 
(defun thgoc (ent pt / param)
(if (setq param (vlax-curve-getParamAtPoint ent pt))
(- (angle '(0 0 0) (vlax-curve-getFirstDeriv ent param)) (/ pi 2))
nil)
)
(defun laydinh(v / n L node)
(setq v (vlax-ename->vla-object v)
n -1 L nil)
(vl-catch-all-error-p (vl-catch-all-apply '(lambda() 
(while (setq node (vla-get-Coordinate v (setq n (1+ n)))) 
(setq L (append L (list (vlax-safearray->list (vlax-variant-value node)))))))))
L
)
 
;;;
(vl-load-com)
(command "undo" "be")
(setq ent (car (entsel "\nChon duong dan:"))
os (getvar 'osmode))
(setvar 'osmode 0)
(prompt "\nChon doi tuong can move:")  
(mapcar '(lambda(x)
(cond ((= "LINE" (dxf 0 x)) (getNear x ent)
(command "move" x "" (car tm) tm1)
(command "rotate" x "" tm1 "r" tm1 (polar tm1 (angle (car tm) (last tm)) 1) (polar tm1 (thgoc ent tm1) 1)))
 
((vl-string-search "LINE" (dxf 0 x)) (getNear x ent) 
(command "move" x "" (car tm) tm1)
(setq tm2 (if (< (distance tm1 (car (setq tm3 (laydinh x)))) 0.1) (nth 1 tm3) (nth (- (length tm3) 2) tm3)))
(command "rotate" x "" tm1 "r" tm1 (polar tm1 (angle tm1 tm2) 1)
(polar tm1 (thgoc ent tm1) 1)))
 
((vl-string-search "TEXT" (dxf 0 x))
(command "move" x "" (dxf 10 x) (setq tm1 (vlax-curve-getClosestPointTo ent (dxf 10 x))))
(command "rotate" x "" tm1 "r" tm1 (polar tm1 (dxf 50 x) 1) (polar tm1 (thgoc ent tm1) 1)))
 
)) (acet-ss-to-list (ssget '((0 . "*LINE,*TEXT"))))
)
(command "undo" "e") (setvar 'osmode os) (princ)
)

Thảo luận gốc

Lisp được chia sẻ trong chủ đề [yêu cầu] Lips move line; pline; vuông góc với line hay pline có sẵn. Xem đúng bài viết #297915 để đọc hướng dẫn và trao đổi thêm.

Về Thư viện AutoLisp (trang 161)