Lisp lệnh TL trong chủ đề “Hỏi về Lisp (thuật toán, ý tưởng, coding,...)”
Các bạn cho tôi hỏi về vấn đề này với.
đây là lisp vẽ tatuy mà tôi dùng rất hữu ích
nhưng có 1 điều là khi tôi muồn vẽ taluy có thông số khác với thông số của taluy ban đầu thì tôi lại ko biết cách thay đổi thông số của taluy
xin hãy giúp tôi.
;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/index.php?showtopic=5947&st=20
;;;;;;;;;vtl;;;;;;;;;;;;;;;;
;Ve ta luy.lenh VTL1
(defun nsl ()
(if (/= scale nil)
(progn
(setq thongbao (strcat "Ty le ban ve ?, <1/" (itoa scale) ">:"))
(if (not (setq scaletmp (getint thongbao)))
(setq scaletmp scale)
)
)
(progn
(setq thongbao "Ty le ban ve ? <1/1000>:")
(if (not (setq scaletmp (getint thongbao)))
(setq scaletmp 1000)
)
)
)
(setq scale scaletmp)
(setq Defaultdist (* (* scale 2) 0.002))
(if (setq tg (getreal (strcat "\nKhoang cach ky hieu ta luy <" (rtos Defaultdist 2 2) ">:")))
(setq Defaultdist tg)
)
(setq chieutaluy1 1 sodoan 0)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun nsl1 ()
(if (not ktdoantaluy1)
(setq ktdoantaluy1 250 tg (getreal (strcat "\nChi\U+1EC1u d\U+00E0i \U+0111o\U+1EA1n ng\U+1EAFn<" (rtos ktdoantaluy1 2 2) ">:")))
)
(if tg
(setq ktdoantaluy1 tg tg nil)
)
(if (not ktdoantaluy2)
(setq ktdoantaluy2 500 tg (getreal (strcat "\nChi\U+1EC1u d\U+00E0i \U+0111o\U+1EA1n d\U+00E0i<" (rtos ktdoantaluy2 2 2) ">:")))
)
(if tg
(setq ktdoantaluy2 tg tg nil)
)
(if (not khoangcachtl)
(setq khoangcachtl 200 tg (getreal (strcat "\Kho\U+1EA3ng c\U+00E1ch gi\U+1EEFa c\U+00E1c \U+0111o\U+1EA1n<" (rtos khoangcachtl 2 2) ">:")))
)
(if tg
(setq khoangcachtl tg tg nil)
)
(if (not sodoanngan)
(setq sodoanngan 1 tg (getint (strcat "\nS\U+1ED1 \U+0111o\U+1EA1n ng\U+1EAFn tr\U+00EAn m\U+1ED9t \U+0111o\U+1EA1n d\U+00E0<" (rtos sodoanngan 2 0) ">:")))
)
(if tg
(setq sodoanngan tg tg nil)
)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(Defun PlMake (Plist) ; Create polyline entities
(entmake '((0 . "POLYLINE")))
(setq n (length Plist)
ic 0
)
(while (< ic n)
(entmake (list (cons 0 "VERTEX") (cons 10 (nth ic Plist))))
(setq ic (1+ ic)
)
)
(entmake '((0 . "SEQEND")))
)
;;;----------------------------------------------------------------
(defun ve1doantaluy (p1 p2 / pvt diemcu ktdoantaluy ketthuc)
(setq pvt (+ (angle p1 p2) (* (/ pi 2) chieutaluy)))
;;;;(setq ketthuc 1)
(if (< sodoan sodoanngan)
(progn
(setq ktdoantaluy ktdoantaluy1)
(setq sodoan (1+ sodoan))
)
(progn
(setq ktdoantaluy ktdoantaluy2)
(setq sodoan 0)
)
)
(setq p2 (polar p1 pvt ktdoantaluy))
(plmake (list p1 p2))
(setq dem (1+ dem))
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(Defun xddsd (com epl kc / e0 e p dsd)
(setq e0 (entlast))
(while e0
(setq e e0)
(setq e0 (entnext e0))
)
(command com epl kc)
(setq e (entnext e))
(while e
(setq p (cdr (assoc 10 (entget e))))
(if p
(setq dsd (cons p dsd))
)
(setq e (entnext e))
)
(command "_.Undo" 1)
(setq dsd dsd)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; ve ta luy cho 1 doi tuong
(Defun vetaluy (ep / le e ketthuc them dsd thutu)
(setq dem 0)
(setq sodoan 0)
(setq ss (ssadd))
(setq e (entget (car ep)))
(if (or (= (cdr (assoc 0 e)) "LWPOLYLINE")
(= (cdr (assoc 0 e)) "POLYLINE")
(= (cdr (assoc 0 e)) "SPLINE")
(= (cdr (assoc 0 e)) "LINE")
(= (cdr (assoc 0 e)) "ARC")
(= (cdr (assoc 0 e)) "CIRCLE")
)
(setq ketthuc 1)
(prompt "\nDoi tuong duoc chon khong hop le")
)
(if ketthuc
(progn
(setq thutu 0)
(setq dsd (xddsd "_.Measure" ep khoangcachtl))
(setq dsd (append dsd (list (vlax-curve-getstartpoint (car ep)))))
(setq p1 (car dsd))
(repeat (1- (length dsd))
(setq thutu (1+ thutu))
(setq p2 (nth thutu dsd))
(ve1doantaluy p1 p2)
(setq p1 p2)
(setq ss (ssadd (entlast) ss))
)
)
)
(setq dem dem)
)
;;;==================================================
(Defun C:TL (/ ep chon lai solan chon ss tg)
(vl-load-com)
(setvar "cmdecho" 0)
(setvar "blipmode" 0)
(command "undo" "g")
;;;;(nsl)
(setq ep 1)
(while ep
(setq solan 0 chieutaluy 1)
(setq ep (entsel "\nCh\U+1ECDn \U+0111\U+1ED1i t\U+01B0\U+1EE3ng v\U+1EBD ta luy..."))
(if ep
(progn
(nsl1)
(setq solan (vetaluy ep))
(initget "Undo Change")
(while
(setq chon (getkword "Undo/Change <enter for exit>: "))
(if (= chon "Undo")
(command "_.Undo" solan)
)
(if (= chon "Change")
(progn
(nsl1)
(setq chieutaluy -1)
(command "_.Undo" solan)
(setq solan (vetaluy ep))
)
)
(initget "Undo Change")
)
(setq blname (getstring t "\nNh\U+1EADp t\U+00EAn block m\U+1ED1n t\U+1EA1o: "))
(if (/= blname "")
(command "block" blname (list 0.0 0.0 0.0) ss "")
)
(setq ep nil)
)
)
)
(command "undo" "e")
(princ)
)
;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/index.php?showtopic=5947&st=20
;;;;;;;;;vtl;;;;;;;;;;;;;;;;
;Ve ta luy.lenh VTL1
(defun nsl ()
(if (/= scale nil)
(progn
(setq thongbao (strcat "Ty le ban ve ?, <1/" (itoa scale) ">:"))
(if (not (setq scaletmp (getint thongbao)))
(setq scaletmp scale)
)
)
(progn
(setq thongbao "Ty le ban ve ? <1/1000>:")
(if (not (setq scaletmp (getint thongbao)))
(setq scaletmp 1000)
)
)
)
(setq scale scaletmp)
(setq Defaultdist (* (* scale 2) 0.002))
(if (setq tg (getreal (strcat "\nKhoang cach ky hieu ta luy <" (rtos Defaultdist 2 2) ">:")))
(setq Defaultdist tg)
)
(setq chieutaluy1 1 sodoan 0)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun nsl1 ()
(if (not ktdoantaluy1)
(setq ktdoantaluy1 250 tg (getreal (strcat "\nChi\U+1EC1u d\U+00E0i \U+0111o\U+1EA1n ng\U+1EAFn<" (rtos ktdoantaluy1 2 2) ">:")))
)
(if tg
(setq ktdoantaluy1 tg tg nil)
)
(if (not ktdoantaluy2)
(setq ktdoantaluy2 500 tg (getreal (strcat "\nChi\U+1EC1u d\U+00E0i \U+0111o\U+1EA1n d\U+00E0i<" (rtos ktdoantaluy2 2 2) ">:")))
)
(if tg
(setq ktdoantaluy2 tg tg nil)
)
(if (not khoangcachtl)
(setq khoangcachtl 200 tg (getreal (strcat "\Kho\U+1EA3ng c\U+00E1ch gi\U+1EEFa c\U+00E1c \U+0111o\U+1EA1n<" (rtos khoangcachtl 2 2) ">:")))
)
(if tg
(setq khoangcachtl tg tg nil)
)
(if (not sodoanngan)
(setq sodoanngan 1 tg (getint (strcat "\nS\U+1ED1 \U+0111o\U+1EA1n ng\U+1EAFn tr\U+00EAn m\U+1ED9t \U+0111o\U+1EA1n d\U+00E0<" (rtos sodoanngan 2 0) ">:")))
)
(if tg
(setq sodoanngan tg tg nil)
)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(Defun PlMake (Plist) ; Create polyline entities
(entmake '((0 . "POLYLINE")))
(setq n (length Plist)
ic 0
)
(while (< ic n)
(entmake (list (cons 0 "VERTEX") (cons 10 (nth ic Plist))))
(setq ic (1+ ic)
)
)
(entmake '((0 . "SEQEND")))
)
;;;----------------------------------------------------------------
(defun ve1doantaluy (p1 p2 / pvt diemcu ktdoantaluy ketthuc)
(setq pvt (+ (angle p1 p2) (* (/ pi 2) chieutaluy)))
;;;;(setq ketthuc 1)
(if (< sodoan sodoanngan)
(progn
(setq ktdoantaluy ktdoantaluy1)
(setq sodoan (1+ sodoan))
)
(progn
(setq ktdoantaluy ktdoantaluy2)
(setq sodoan 0)
)
)
(setq p2 (polar p1 pvt ktdoantaluy))
(plmake (list p1 p2))
(setq dem (1+ dem))
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(Defun xddsd (com epl kc / e0 e p dsd)
(setq e0 (entlast))
(while e0
(setq e e0)
(setq e0 (entnext e0))
)
(command com epl kc)
(setq e (entnext e))
(while e
(setq p (cdr (assoc 10 (entget e))))
(if p
(setq dsd (cons p dsd))
)
(setq e (entnext e))
)
(command "_.Undo" 1)
(setq dsd dsd)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; ve ta luy cho 1 doi tuong
(Defun vetaluy (ep / le e ketthuc them dsd thutu)
(setq dem 0)
(setq sodoan 0)
(setq ss (ssadd))
(setq e (entget (car ep)))
(if (or (= (cdr (assoc 0 e)) "LWPOLYLINE")
(= (cdr (assoc 0 e)) "POLYLINE")
(= (cdr (assoc 0 e)) "SPLINE")
(= (cdr (assoc 0 e)) "LINE")
(= (cdr (assoc 0 e)) "ARC")
(= (cdr (assoc 0 e)) "CIRCLE")
)
(setq ketthuc 1)
(prompt "\nDoi tuong duoc chon khong hop le")
)
(if ketthuc
(progn
(setq thutu 0)
(setq dsd (xddsd "_.Measure" ep khoangcachtl))
(setq dsd (append dsd (list (vlax-curve-getstartpoint (car ep)))))
(setq p1 (car dsd))
(repeat (1- (length dsd))
(setq thutu (1+ thutu))
(setq p2 (nth thutu dsd))
(ve1doantaluy p1 p2)
(setq p1 p2)
(setq ss (ssadd (entlast) ss))
)
)
)
(setq dem dem)
)
;;;==================================================
(Defun C:TL (/ ep chon lai solan chon ss tg)
(vl-load-com)
(setvar "cmdecho" 0)
(setvar "blipmode" 0)
(command "undo" "g")
;;;;(nsl)
(setq ep 1)
(while ep
(setq solan 0 chieutaluy 1)
(setq ep (entsel "\nCh\U+1ECDn \U+0111\U+1ED1i t\U+01B0\U+1EE3ng v\U+1EBD ta luy..."))
(if ep
(progn
(nsl1)
(setq solan (vetaluy ep))
(initget "Undo Change")
(while
(setq chon (getkword "Undo/Change <enter for exit>: "))
(if (= chon "Undo")
(command "_.Undo" solan)
)
(if (= chon "Change")
(progn
(nsl1)
(setq chieutaluy -1)
(command "_.Undo" solan)
(setq solan (vetaluy ep))
)
)
(initget "Undo Change")
)
(setq blname (getstring t "\nNh\U+1EADp t\U+00EAn block m\U+1ED1n t\U+1EA1o: "))
(if (/= blname "")
(command "block" blname (list 0.0 0.0 0.0) ss "")
)
(setq ep nil)
)
)
)
(command "undo" "e")
(princ)
)
;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/index.php?showtopic=5947&st=20
;;;;;;;;;vtl;;;;;;;;;;;;;;;;
;Ve ta luy.lenh VTL1
(defun nsl ()
(if (/= scale nil)
(progn
(setq thongbao (strcat "Ty le ban ve ?, <1/" (itoa scale) ">:"))
(if (not (setq scaletmp (getint thongbao)))
(setq scaletmp scale)
)
)
(progn
(setq thongbao "Ty le ban ve ? <1/1000>:")
(if (not (setq scaletmp (getint thongbao)))
(setq scaletmp 1000)
)
)
)
(setq scale scaletmp)
(setq Defaultdist (* (* scale 2) 0.002))
(if (setq tg (getreal (strcat "\nKhoang cach ky hieu ta luy <" (rtos Defaultdist 2 2) ">:")))
(setq Defaultdist tg)
)
(setq chieutaluy1 1 sodoan 0)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun nsl1 ()
(if (not ktdoantaluy1)
(setq ktdoantaluy1 250 tg (getreal (strcat "\nChi\U+1EC1u d\U+00E0i \U+0111o\U+1EA1n ng\U+1EAFn<" (rtos ktdoantaluy1 2 2) ">:")))
)
(if tg
(setq ktdoantaluy1 tg tg nil)
)
(if (not ktdoantaluy2)
(setq ktdoantaluy2 500 tg (getreal (strcat "\nChi\U+1EC1u d\U+00E0i \U+0111o\U+1EA1n d\U+00E0i<" (rtos ktdoantaluy2 2 2) ">:")))
)
(if tg
(setq ktdoantaluy2 tg tg nil)
)
(if (not khoangcachtl)
(setq khoangcachtl 200 tg (getreal (strcat "\Kho\U+1EA3ng c\U+00E1ch gi\U+1EEFa c\U+00E1c \U+0111o\U+1EA1n<" (rtos khoangcachtl 2 2) ">:")))
)
(if tg
(setq khoangcachtl tg tg nil)
)
(if (not sodoanngan)
(setq sodoanngan 1 tg (getint (strcat "\nS\U+1ED1 \U+0111o\U+1EA1n ng\U+1EAFn tr\U+00EAn m\U+1ED9t \U+0111o\U+1EA1n d\U+00E0<" (rtos sodoanngan 2 0) ">:")))
)
(if tg
(setq sodoanngan tg tg nil)
)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(Defun PlMake (Plist) ; Create polyline entities
(entmake '((0 . "POLYLINE")))
(setq n (length Plist)
ic 0
)
(while (< ic n)
(entmake (list (cons 0 "VERTEX") (cons 10 (nth ic Plist))))
(setq ic (1+ ic)
)
)
(entmake '((0 . "SEQEND")))
)
;;;----------------------------------------------------------------
(defun ve1doantaluy (p1 p2 / pvt diemcu ktdoantaluy ketthuc)
(setq pvt (+ (angle p1 p2) (* (/ pi 2) chieutaluy)))
;;;;(setq ketthuc 1)
(if (< sodoan sodoanngan)
(progn
(setq ktdoantaluy ktdoantaluy1)
(setq sodoan (1+ sodoan))
)
(progn
(setq ktdoantaluy ktdoantaluy2)
(setq sodoan 0)
)
)
(setq p2 (polar p1 pvt ktdoantaluy))
(plmake (list p1 p2))
(setq dem (1+ dem))
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(Defun xddsd (com epl kc / e0 e p dsd)
(setq e0 (entlast))
(while e0
(setq e e0)
(setq e0 (entnext e0))
)
(command com epl kc)
(setq e (entnext e))
(while e
(setq p (cdr (assoc 10 (entget e))))
(if p
(setq dsd (cons p dsd))
)
(setq e (entnext e))
)
(command "_.Undo" 1)
(setq dsd dsd)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; ve ta luy cho 1 doi tuong
(Defun vetaluy (ep / le e ketthuc them dsd thutu)
(setq dem 0)
(setq sodoan 0)
(setq ss (ssadd))
(setq e (entget (car ep)))
(if (or (= (cdr (assoc 0 e)) "LWPOLYLINE")
(= (cdr (assoc 0 e)) "POLYLINE")
(= (cdr (assoc 0 e)) "SPLINE")
(= (cdr (assoc 0 e)) "LINE")
(= (cdr (assoc 0 e)) "ARC")
(= (cdr (assoc 0 e)) "CIRCLE")
)
(setq ketthuc 1)
(prompt "\nDoi tuong duoc chon khong hop le")
)
(if ketthuc
(progn
(setq thutu 0)
(setq dsd (xddsd "_.Measure" ep khoangcachtl))
(setq dsd (append dsd (list (vlax-curve-getstartpoint (car ep)))))
(setq p1 (car dsd))
(repeat (1- (length dsd))
(setq thutu (1+ thutu))
(setq p2 (nth thutu dsd))
(ve1doantaluy p1 p2)
(setq p1 p2)
(setq ss (ssadd (entlast) ss))
)
)
)
(setq dem dem)
)
;;;==================================================
(Defun C:TL (/ ep chon lai solan chon ss tg)
(vl-load-com)
(setvar "cmdecho" 0)
(setvar "blipmode" 0)
(command "undo" "g")
;;;;(nsl)
(setq ep 1)
(while ep
(setq solan 0 chieutaluy 1)
(setq ep (entsel "\nCh\U+1ECDn \U+0111\U+1ED1i t\U+01B0\U+1EE3ng v\U+1EBD ta luy..."))
(if ep
(progn
(nsl1)
(setq solan (vetaluy ep))
(initget "Undo Change")
(while
(setq chon (getkword "Undo/Change <enter for exit>: "))
(if (= chon "Undo")
(command "_.Undo" solan)
)
(if (= chon "Change")
(progn
(nsl1)
(setq chieutaluy -1)
(command "_.Undo" solan)
(setq solan (vetaluy ep))
)
)
(initget "Undo Change")
)
(setq blname (getstring t "\nNh\U+1EADp t\U+00EAn block m\U+1ED1n t\U+1EA1o: "))
(if (/= blname "")
(command "block" blname (list 0.0 0.0 0.0) ss "")
)
(setq ep nil)
)
)
)
(command "undo" "e")
(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
- Chép mã nguồn, lưu thành tệp 289565_tl.lsp.
- 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ẽ.
- Gõ lệnh TL để chạy lisp.
Mã nguồn 289565_tl.lsp (trích từ bài viết gốc)
;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/index.php?showtopic=5947&st=20
;;;;;;;;;vtl;;;;;;;;;;;;;;;;
;Ve ta luy.lenh VTL1
(defun nsl ()
(if (/= scale nil)
(progn
(setq thongbao (strcat "Ty le ban ve ?, <1/" (itoa scale) ">:"))
(if (not (setq scaletmp (getint thongbao)))
(setq scaletmp scale)
)
)
(progn
(setq thongbao "Ty le ban ve ? <1/1000>:")
(if (not (setq scaletmp (getint thongbao)))
(setq scaletmp 1000)
)
)
)
(setq scale scaletmp)
(setq Defaultdist (* (* scale 2) 0.002))
(if (setq tg (getreal (strcat "\nKhoang cach ky hieu ta luy <" (rtos Defaultdist 2 2) ">:")))
(setq Defaultdist tg)
)
(setq chieutaluy1 1 sodoan 0)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun nsl1 ()
(if (not ktdoantaluy1)
(setq ktdoantaluy1 250 tg (getreal (strcat "\nChi\U+1EC1u d\U+00E0i \U+0111o\U+1EA1n ng\U+1EAFn<" (rtos ktdoantaluy1 2 2) ">:")))
)
(if tg
(setq ktdoantaluy1 tg tg nil)
)
(if (not ktdoantaluy2)
(setq ktdoantaluy2 500 tg (getreal (strcat "\nChi\U+1EC1u d\U+00E0i \U+0111o\U+1EA1n d\U+00E0i<" (rtos ktdoantaluy2 2 2) ">:")))
)
(if tg
(setq ktdoantaluy2 tg tg nil)
)
(if (not khoangcachtl)
(setq khoangcachtl 200 tg (getreal (strcat "\Kho\U+1EA3ng c\U+00E1ch gi\U+1EEFa c\U+00E1c \U+0111o\U+1EA1n<" (rtos khoangcachtl 2 2) ">:")))
)
(if tg
(setq khoangcachtl tg tg nil)
)
(if (not sodoanngan)
(setq sodoanngan 1 tg (getint (strcat "\nS\U+1ED1 \U+0111o\U+1EA1n ng\U+1EAFn tr\U+00EAn m\U+1ED9t \U+0111o\U+1EA1n d\U+00E0<" (rtos sodoanngan 2 0) ">:")))
)
(if tg
(setq sodoanngan tg tg nil)
)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(Defun PlMake (Plist) ; Create polyline entities
(entmake '((0 . "POLYLINE")))
(setq n (length Plist)
ic 0
)
(while (< ic n)
(entmake (list (cons 0 "VERTEX") (cons 10 (nth ic Plist))))
(setq ic (1+ ic)
)
)
(entmake '((0 . "SEQEND")))
)
;;;----------------------------------------------------------------
(defun ve1doantaluy (p1 p2 / pvt diemcu ktdoantaluy ketthuc)
(setq pvt (+ (angle p1 p2) (* (/ pi 2) chieutaluy)))
;;;;(setq ketthuc 1)
(if (< sodoan sodoanngan)
(progn
(setq ktdoantaluy ktdoantaluy1)
(setq sodoan (1+ sodoan))
)
(progn
(setq ktdoantaluy ktdoantaluy2)
(setq sodoan 0)
)
)
(setq p2 (polar p1 pvt ktdoantaluy))
(plmake (list p1 p2))
(setq dem (1+ dem))
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(Defun xddsd (com epl kc / e0 e p dsd)
(setq e0 (entlast))
(while e0
(setq e e0)
(setq e0 (entnext e0))
)
(command com epl kc)
(setq e (entnext e))
(while e
(setq p (cdr (assoc 10 (entget e))))
(if p
(setq dsd (cons p dsd))
)
(setq e (entnext e))
)
(command "_.Undo" 1)
(setq dsd dsd)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; ve ta luy cho 1 doi tuong
(Defun vetaluy (ep / le e ketthuc them dsd thutu)
(setq dem 0)
(setq sodoan 0)
(setq ss (ssadd))
(setq e (entget (car ep)))
(if (or (= (cdr (assoc 0 e)) "LWPOLYLINE")
(= (cdr (assoc 0 e)) "POLYLINE")
(= (cdr (assoc 0 e)) "SPLINE")
(= (cdr (assoc 0 e)) "LINE")
(= (cdr (assoc 0 e)) "ARC")
(= (cdr (assoc 0 e)) "CIRCLE")
)
(setq ketthuc 1)
(prompt "\nDoi tuong duoc chon khong hop le")
)
(if ketthuc
(progn
(setq thutu 0)
(setq dsd (xddsd "_.Measure" ep khoangcachtl))
(setq dsd (append dsd (list (vlax-curve-getstartpoint (car ep)))))
(setq p1 (car dsd))
(repeat (1- (length dsd))
(setq thutu (1+ thutu))
(setq p2 (nth thutu dsd))
(ve1doantaluy p1 p2)
(setq p1 p2)
(setq ss (ssadd (entlast) ss))
)
)
)
(setq dem dem)
)
;;;==================================================
(Defun C:TL (/ ep chon lai solan chon ss tg)
(vl-load-com)
(setvar "cmdecho" 0)
(setvar "blipmode" 0)
(command "undo" "g")
;;;;(nsl)
(setq ep 1)
(while ep
(setq solan 0 chieutaluy 1)
(setq ep (entsel "\nCh\U+1ECDn \U+0111\U+1ED1i t\U+01B0\U+1EE3ng v\U+1EBD ta luy..."))
(if ep
(progn
(nsl1)
(setq solan (vetaluy ep))
(initget "Undo Change")
(while
(setq chon (getkword "Undo/Change <enter for exit>: "))
(if (= chon "Undo")
(command "_.Undo" solan)
)
(if (= chon "Change")
(progn
(nsl1)
(setq chieutaluy -1)
(command "_.Undo" solan)
(setq solan (vetaluy ep))
)
)
(initget "Undo Change")
)
(setq blname (getstring t "\nNh\U+1EADp t\U+00EAn block m\U+1ED1n t\U+1EA1o: "))
(if (/= blname "")
(command "block" blname (list 0.0 0.0 0.0) ss "")
)
(setq ep nil)
)
)
)
(command "undo" "e")
(princ)
)Thảo luận gốc
Lisp được chia sẻ trong chủ đề Hỏi về Lisp (thuật toán, ý tưởng, coding,...). Xem đúng bài viết #289565 để đọc hướng dẫn và trao đổi thêm.