Jump to content

Yêu cầu-Lisp gắn cao độ vào đỉnh polyline,tra CD tại điểm pick trên 3d polyline

mình co lisp này bạn xem thế nào

lisp điền cao độ và khoảng cách lẻ do mình sưu tầm và chỉnh sửa lisp này dùng để điền trắc ngang

lisp đây:

(command "layer" "n" "Duong giong" "c" "8" "Duong giong" "")
(command "layer" "n" "CDTN" "c" "4" "CDTN" "")
(command "layer" "n" "KCL" "c" "6" "KCL" "")
;
(defun C:VV ()
  (setq eclast (getvar "CMDECHO"))
  (setq lalast (getvar "CLAYER"))
  (setq oslast (getvar "OSMODE"))
  (setvar "CMDECHO" 0)
;********************************************************************************
  (setvar "osmode" 512)
  (setq po (getpoint "\nDuong ghi cao do <nearest to>_ "))
  (setq yo (cadr po))
  (setq pk (getpoint "\nDuong ghi khoang cach <nearest to>_ "))
  (setq yk (cadr pk))
  (setvar "osmode" 33)
  (setq pc (getpoint "\nDiem chuan <end, int >_ ") )
  (setq xc (car pc) yc (cadr pc))
  ;(setq hc (getreal "\nCao do chuan: "))
  (setq hc (entsel "\ncao do cos chuan"))
	(while
 	 (or
   	 (null hc)
   	 (/= "TEXT" (cdr (assoc 0 (entget (car hc)))))
	 )
	(princ "\nDoi tuong khong phai la text! Chon lai")
 	(setq hc (entsel "\ncao do cos chuan"))
	)
  (setq hc (cdr (assoc 1 (entget (car hc))))) 
  (setq hc (atof hc))
  (setvar "osmode" 33)
  (command "style" "chuso" "" 0.4 "" "" "" "" "" )
  (setq ent (car (entsel "\nChon duong Polyline muon dien:")))
  (if (= (cdr (assoc 0 (entget ent))) "POLYLINE")
    (progn
      (setq ent (entnext ent))
      (setq xx 0)
      (setq toado (cdr (assoc 10 (entget ent)))
	      x (car toado)
	      y (cadr toado)
      )
      (setq h (- y (- yc hc)))
      (setq d (abs (- x xc)))
      (if (< x xc) (setq xx -1))
      (if (> x xc) (setq xx 1))
      (setvar  "osmode" 0)
      (command "layer" "s" "Duong giong" "")
      (command "line" (list x y) (list x yo) "")
      (command "layer" "s" "CDTN" "")
      (command "text" "mr" (list x (- yo 0.2)) 90 (rtos h 2 2))
      (command "layer" "s" "KCL" "")
      (command "line" (list x yk) (list x (- yk 1.4)) "")      
      (setq ent (entnext ent))
	  (setq xc x)
      (while (/= "SEQEND" (cdr (assoc 0 (entget (entnext ent)))))
	(setq toado (cdr (assoc 10 (entget ent)))
	      x (car toado)
	      y (cadr toado)
	)
	(setq h (- y (- yc hc)))
	(setq d (abs (- x xc)))
	(if (< x xc) (setq xx -1))
	(if (> x xc) (setq xx 1))
	(setvar  "osmode" 0)
	(command "layer" "s" "Duong giong" "")
	(command "line" (list x y) (list x yo) "")
	(command "layer" "s" "CDTN" "")
	(if (>= d 1)
	  (progn
	    (command "text" "mr" (list x (- yo 0.2)) 90 (rtos h 2 2))
	    (command "layer" "s" "KCL" "")
	    (command "line" (list x yk) (list x (- yk 1.4)) "")
	    (command "text" "mc" (list (/ (+ x xc) 2) (- yk 0.7)) 0 (rtos d 2 2))
	  )
	  (progn
	    (if (> d 0)
	      (progn
	      (command "layer" "s" "KCL" "")
	      (command "text" "mc" (list (/ (+ x xc) 2) (- yk 0.7)) 90 (rtos d 2 2))
	    ))
	    (command "layer" "s" "KCL" "")
	    (command "line" (list x yk) (list x (- yk 1.4)) "")
	    (if (> d 0.4)
	      (progn
		(command "layer" "s" "CDTN" "")
	      (command "text" "mr" (list x (- yo 0.2)) 90 (rtos h 2 2))
		)
	      (progn
		(command "layer" "s" "KCL" "")
	      (command "text" "mr" (list (+ x (* xx (- 0.4 d))) (- yo 0.2)) 90 (rtos h 2 2))
	    ))
	  )
	)
	(setq xc x)
	(setvar "osmode" 33)
	(setq ent (entnext ent))
      )
	   (while (= "SEQEND" (cdr (assoc 0 (entget (entnext ent)))))
	(setq toado (cdr (assoc 10 (entget ent)))
	      x (car toado)
	      y (cadr toado)
	)
	(setq h (- y (- yc hc)))
	(setq d (abs (- x xc)))
	(if (< x xc) (setq xx -1))
	(if (> x xc) (setq xx 1))
	(setvar  "osmode" 0)
	(command "layer" "s" "Duong giong" "")
	(command "line" (list x y) (list x yo) "")
	(command "layer" "s" "CDTN" "")
	(if (>= d 1)
	  (progn
	    (command "text" "mr" (list x (- yo 0.2)) 90 (rtos h 2 2))
	    (command "layer" "s" "KCL" "")
	    (command "line" (list x yk) (list x (- yk 1.4)) "")
	    (command "text" "mc" (list (/ (+ x xc) 2) (- yk 0.7)) 0 (rtos d 2 2))
	  )
	  (progn
	    (if (> d 0)
	      (progn
	      (command "layer" "s" "KCL" "")
	      (command "text" "mc" (list (/ (+ x xc) 2) (- yk 0.7)) 90 (rtos d 2 2))
	    ))
	    (command "layer" "s" "KCL" "")
	    (command "line" (list x yk) (list x (- yk 1.4)) "")
	    (if (> d 0.4)
	      (progn
		(command "layer" "s" "CDTN" "")
	      (command "text" "mr" (list x (- yo 0.2)) 90 (rtos h 2 2))
		)
	      (progn
		(command "layer" "s" "KCL" "")
	      (command "text" "mr" (list (+ x (* xx (- 0.4 d))) (- yo 0.2)) 90 (rtos h 2 2))
	    ))
	  )
	)
	(setq xc x)
	(setvar "osmode" 33)
	(setq ent (entnext ent))
      )
    )
  )
;-----------------------------------------------------------------------------------
  (if (= (cdr (assoc 0 (entget ent))) "LWPOLYLINE")
    (progn
      (command ".convertpoly" "h" ent "")
      (setq ent (entnext ent))
      (setq xx 0)
      (setq toado (cdr (assoc 10 (entget ent)))
	      x (car toado)
	      y (cadr toado)
      )
      (setq h (- y (- yc hc)))
      (setq d (abs (- x xc)))
      (if (< x xc) (setq xx -1))
      (if (> x xc) (setq xx 1))
      (setvar  "osmode" 0)
      (command "layer" "s" "Duong giong" "")
      (command "line" (list x y) (list x yo) "")
      (command "layer" "s" "CDTN" "")
      (command "text" "mr" (list x (- yo 0.2)) 90 (rtos h 2 2))
      (command "layer" "s" "KCL" "")
      (command "line" (list x yk) (list x (- yk 1.4)) "")      
      (setq ent (entnext ent))
	  (setq xc x)
      (while (/= "SEQEND" (cdr (assoc 0 (entget (entnext ent)))))
	(setq toado (cdr (assoc 10 (entget ent)))
	      x (car toado)
	      y (cadr toado)
	)
	(setq h (- y (- yc hc)))
	(setq d (abs (- x xc)))
	(if (< x xc) (setq xx -1))
	(if (> x xc) (setq xx 1))
	(setvar  "osmode" 0)
	(command "layer" "s" "Duong giong" "")
	(command "line" (list x y) (list x yo) "")
	(command "layer" "s" "CDTN" "")
	(if (>= d 1)
	  (progn
	    (command "text" "mr" (list x (- yo 0.2)) 90 (rtos h 2 2))
	    (command "layer" "s" "KCL" "")
	    (command "line" (list x yk) (list x (- yk 1.4)) "")
	    (command "text" "mc" (list (/ (+ x xc) 2) (- yk 0.7)) 0 (rtos d 2 2))
	  )
	  (progn
	    (if (> d 0)
	      (progn
	      (command "layer" "s" "KCL" "")
	      (command "text" "mc" (list (/ (+ x xc) 2) (- yk 0.7)) 90 (rtos d 2 2))
	    ))
	    (command "layer" "s" "KCL" "")
	    (command "line" (list x yk) (list x (- yk 1.4)) "")
	    (if (> d 0.4)
	      (progn
		(command "layer" "s" "CDTN" "")
	      (command "text" "mr" (list x (- yo 0.2)) 90 (rtos h 2 2))
		)
	      (progn
		(command "layer" "s" "KCL" "")
	      (command "text" "mr" (list (+ x (* xx (- 0.4 d))) (- yo 0.2)) 90 (rtos h 2 2))
	    ))
	  )
	)
	(setq xc x)
	(setvar "osmode" 33)
	(setq ent (entnext ent))
      )
	   (while (= "SEQEND" (cdr (assoc 0 (entget (entnext ent)))))
	(setq toado (cdr (assoc 10 (entget ent)))
	      x (car toado)
	      y (cadr toado)
	)
	(setq h (- y (- yc hc)))
	(setq d (abs (- x xc)))
	(if (< x xc) (setq xx -1))
	(if (> x xc) (setq xx 1))
	(setvar  "osmode" 0)
	(command "layer" "s" "Duong giong" "")
	(command "line" (list x y) (list x yo) "")
	(command "layer" "s" "CDTN" "")
	(if (>= d 1)
	  (progn
	    (command "text" "mr" (list x (- yo 0.2)) 90 (rtos h 2 2))
	    (command "layer" "s" "KCL" "")
	    (command "line" (list x yk) (list x (- yk 1.4)) "")
	    (command "text" "mc" (list (/ (+ x xc) 2) (- yk 0.7)) 0 (rtos d 2 2))
	  )
	  (progn
	    (if (> d 0)
	      (progn
	      (command "layer" "s" "KCL" "")
	      (command "text" "mc" (list (/ (+ x xc) 2) (- yk 0.7)) 90 (rtos d 2 2))
	    ))
	    (command "layer" "s" "KCL" "")
	    (command "line" (list x yk) (list x (- yk 1.4)) "")
	    (if (> d 0.4)
	      (progn
		(command "layer" "s" "CDTN" "")
	      (command "text" "mr" (list x (- yo 0.2)) 90 (rtos h 2 2))
		)
	      (progn
		(command "layer" "s" "KCL" "")
	      (command "text" "mr" (list (+ x (* xx (- 0.4 d))) (- yo 0.2)) 90 (rtos h 2 2))
	    ))
	  )
	)
	(setq xc x)
	(setvar "osmode" 33)
	(setq ent (entnext ent))
      )
    )
  (command ".convert" "p" "s" ent "")
  )  
;********************************************************************************
  (setvar "OSMODE" oslast)
  (setvar "CLAYER" lalast)
  (setvar "CMDECHO" eclast)
)
;*****************************************

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 246440_vv.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 VV để chạy lisp.

Thảo luận gốc

Bài viết gốc #246440 không còn trên diễn đàn.

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