Lisp lệnh PTEST trong chủ đề “help: làm sao để chia một đường polyline thành các đoạn có chiều dài khác nhau?”
(defun C:PTEST() ;;;--- Get the entity's name (setq en(car(entsel "\n Select a PolyLine: "))) ;;;--- Get the DXF group codes of the entity (setq enlist(entget en)) ;;;--- Create an empty list to hold the points (setq ptList(list)) ;;;--- Get the sub-entities name (setq en2(entnext en)) ;;;--- Get the dxf group codes of the sub-entity (setq enlist2(entget en2)) (setq ptList(append ptList (list (cdr(assoc 10 enlist2))))) ;;;--- While the polyline has a next vertice (while (not (equal (cdr(assoc 0 (entget(entnext en2))))"SEQEND")) ;;;--- Get the next sub-entity (setq en2(entnext en2)) ;;;--- Get its dxf group codes (setq enlist2(entget en2)) ;;;--- Check to make sure it is not a spline reference point (if(/= 16 (cdr(assoc 70 enlist2))) ;;;--- It is a vertex, save the point in a list (setq ptList(append ptList (list (cdr(assoc 10 enlist2))))) ) ) (setq olmode (getvar "pdmode")) (setvar "pdmode" 3) (setq n 0) (while (nth (1+ n) ptlist) (setq p1 (nth n ptlist) p2 (nth (1+ n) ptlist) x1 (car p1) y1 (cadr p1) x2 (car p2) y2 (cadr p2) k 1 goc (angle p1 p2) a (getreal "\n Nhap khoang cach cho block thu nhat : ") b (getreal "\n Nhap khoang cach cho block thu hai :") ) (setq p3 (list (+ x1 (* a (cos goc))) (+ y1 (* a (sin goc))))) (command "point" p3) (command "insert" "b" "s" 1 p3 0 "") (setq p4 (list (+ x1 (* (+ a b) (cos goc))) (+ y1 (* (+ a b) (sin goc))))) (command "point" p4) (command "insert" "b" "s" 1 p4 0 "") (setq n (1+ n)) ) (setvar "pdmode" olmode) (princ) )
Chào bạn phamthanhbinh.
Mình muốy nhờ bạn chỉnh giúp mình của Lisp trên,
Để đo khoảng cách và thể hiện điểm đo trên cạnh. Ví như ta có một hình tứ giác chử nhật có chiều dài và rộng, ta chọn hình đó để chia, chọn điểm bắt đầu chia và hướng chia, nhập chiều dài. Thì lisp thực hiện công ciệc xác định điểm đó và vẻ kí hiệu chấm tròn nhỏ, yêu cầu nhập số điểm đó, thể hiện lên số điểm chia đó và khoảng cách,
Lisp thực hiện chia khoảng cách, ghi kí hiệu điểm và chiều dài trên cạnh chia đó.
Rất mong được Bạn giúp
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 74051_ptest.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 PTEST để chạy lisp.
Mã nguồn 74051_ptest.lsp (trích từ bài viết gốc)
(defun C:PTEST()
;;;--- Get the entity's name
(setq en(car(entsel "\n Select a PolyLine: ")))
;;;--- Get the DXF group codes of the entity
(setq enlist(entget en))
;;;--- Create an empty list to hold the points
(setq ptList(list))
;;;--- Get the sub-entities name
(setq en2(entnext en))
;;;--- Get the dxf group codes of the sub-entity
(setq enlist2(entget en2))
(setq ptList(append ptList (list (cdr(assoc 10 enlist2)))))
;;;--- While the polyline has a next vertice
(while (not (equal (cdr(assoc 0 (entget(entnext en2))))"SEQEND"))
;;;--- Get the next sub-entity
(setq en2(entnext en2))
;;;--- Get its dxf group codes
(setq enlist2(entget en2))
;;;--- Check to make sure it is not a spline reference point
(if(/= 16 (cdr(assoc 70 enlist2)))
;;;--- It is a vertex, save the point in a list [ptlist]
(setq ptList(append ptList (list (cdr(assoc 10 enlist2)))))
)
)
(setq olmode (getvar "pdmode"))
(setvar "pdmode" 3)
(setq n 0)
(while (nth (1+ n) ptlist)
(setq p1 (nth n ptlist)
p2 (nth (1+ n) ptlist)
x1 (car p1)
y1 (cadr p1)
x2 (car p2)
y2 (cadr p2)
k 1
goc (angle p1 p2)
a (getreal "\n Nhap khoang cach cho block thu nhat : ")
b (getreal "\n Nhap khoang cach cho block thu hai :")
)
(setq p3 (list (+ x1 (* a (cos goc))) (+ y1 (* a (sin goc)))))
(command "point" p3)
(command "insert" "b" "s" 1 p3 0 "")
(setq p4 (list (+ x1 (* (+ a b) (cos goc))) (+ y1 (* (+ a b) (sin goc)))))
(command "point" p4)
(command "insert" "b" "s" 1 p4 0 "")
(setq n (1+ n))
)
(setvar "pdmode" olmode)
(princ)
)Thảo luận gốc
Lisp được chia sẻ trong chủ đề help: làm sao để chia một đường polyline thành các đoạn có chiều dài khác nhau?. Xem đúng bài viết #74051 để đọc hướng dẫn và trao đổi thêm.