Jump to content

Lisp lệnh ADV EDV trong chủ đề “Entmod Pline Theo Hình Dạng Của Pline Mẫu ( Vẫn Giữ Nguyên Entity Name)”

;;; Add vertext into Polyline and LWPolyline 2010 by Thaistreetz

(defun c:Adv (/ DKCV LST LSTPT N PL PL1 PLS PLSTLAST PT PTA WP)

(if (and (setq PL (car (entsel (TCVN3-Unicode " - Chän ®­êng Pline cÇn thªm ®Ønh ")))) (wcmatch (cdr (assoc 0 (entget PL))) "*POLYLINE"))

(progn

(vl-cmdf "undo" "begin")

(if (= (cdr (assoc 0 (entget PL))) "POLYLINE")

(progn

(setq DKCV T PLSTLAST (getvar "PLINETYPE"))

(setvar "PLINETYPE" 1)

(vl-cmdf "convert" "P" "S" PL "")

(setvar "PLINETYPE" PLSTLAST)

);progn

);if

(setq PLs (ssadd PL (ssadd)))

(while (progn

(sssetfirst nil PLs)

(initget 128 "u")

(setq PTa (getpoint (TCVN3-Unicode "\nPick ®Ønh cÇn thªm ")))

(if (= PTa "u") (progn (prompt "- Undo") (vl-cmdf "undo" "Back")) PTa))

(if (/= PTa "u")

(progn

(vl-cmdf "undo" "mark")

(setq PT (vlax-curve-getPointatParam PL (setq n (fix (vlax-curve-getParamatPoint PL (vlax-curve-getClosestPointto PL (setq PTa (trans PTa 1 0))))))))

(setq Lst nil)

(if (= n 0)

(progn

(setq Lstpt (reverse(acet-geom-pline-point-list PL nil))

PL1 (makeLWPolyline lstpt nil nil nil nil nil nil))

(if (= (fix (vlax-curve-getParamatPoint PL1 (vlax-curve-getClosestPointto PL1 PTa))) (- (length Lstpt) 1))

(mapcar '(lambda (x)

(setq Lst (if (equal x (list 10 (car PT) (cadr PT)) 0.0001)

(cons x (cons (list 10 (car PTa) (cadr PTa)) Lst))

(cons x Lst))))

(entget PL))

(mapcar '(lambda (x)

(setq Lst (if (equal x (list 10 (car PT) (cadr PT)) 0.0001)

(cons (list 10 (car PTa) (cadr PTa)) (cons x Lst))

(cons x Lst))))

(entget PL)))

(entdel PL1))

(mapcar '(lambda (x)

(setq Lst (if (equal x (list 10 (car PT) (cadr PT)) 0.0001)

(cons (list 10 (car PTa) (cadr PTa)) (cons x Lst))

(cons x Lst)))) (entget PL)))

(entmod (reverse Lst))))

);while

(sssetfirst)

(if DKCV (vl-cmdf "CONVERTPOLY" "H" wp "")))

(prompt (TCVN3-Unicode "\n§èi t­îng kh«ng ph¶i Polyline ")));if

(vl-cmdf "undo" "end")

(princ)

);end

;;; remove vertext into Polyline and LWPolyline

;;; copyright 2010 by Gia_Bach

;;; Edited 2010 by thaistreetz

(defun c:edv (/ removenth bulges coords ent idx param pt DKCV PLSTLAST)

(defun removenth (n lst / i rtn)

(setq i -1)

(foreach x lst (if (/= n (setq i (1+ i))) (setq rtn (cons x rtn))))

(reverse rtn))

(vl-cmdf "undo" "begin")

(while (progn

(initget 128 "u")

(setq ent (entsel (TCVN3-Unicode "\nChän ®Ønh Pline cÇn xãa: ")))

(if (= ent "u") (progn (prompt "- Undo") (vl-cmdf "undo" "Back")) ent))

(if (and (/= ent "u") (wcmatch (cdr (assoc 0 (entget (car ent)))) "*POLYLINE"))

(progn

(vl-cmdf "undo" "Mark")

(princ (setq pt (osnap (cadr ent) "near")))

(if (= (cdr (assoc 0 (entget (car ent)))) "POLYLINE")

(progn

(setq DKCV T PLSTLAST (getvar "PLINETYPE"))

(setvar "PLINETYPE" 1)

(vl-cmdf "convert" "P" "S" (car ent) "")

(setvar "PLINETYPE" PLSTLAST)))

(setq ent (vlax-ename->vla-object (car ent))

param (atoi (rtos (vlax-curve-getparamatpoint ent pt) 2 0))

coords (vlax-get ent 'coordinates) idx -1 bulges nil)

(repeat (/ (length coords) 2) (setq bulges (cons (vla-getbulge ent (setq idx (1+ idx))) bulges)))

(setq bulges (removenth param (reverse bulges)))

(repeat 2 (setq coords (removenth (* 2 param) coords)))

(vlax-put ent 'coordinates coords)

(setq idx -1)

(foreach bulge bulges (vla-setbulge ent (setq idx (1+ idx)) bulge))))

);while

(if DKCV (vl-cmdf "CONVERTPOLY" "H" ent ""))

(vl-cmdf "undo" "end")

(princ)

);end

(defun TCVN3-Unicode (stsua / index stdich chuht chusua tapsua)

(if (= (getvar "acadver") "16.1s (LMS Tech)") stsua (progn

(setq tapsua

(list (cons "µ" "\U+00E0")(cons "Ì" "\U+00E8")(cons "ß" "\U+00F2")(cons "ï" "\U+00F9")

(cons "¸" "\U+00E1")(cons "Ð" "\U+00E9")(cons "ã" "\U+00F3")(cons "ó" "\U+00FA")

(cons "¶" "\U+1EA3")(cons "Î" "\U+1EBB")(cons "á" "\U+1ECF")(cons "ñ" "\U+1EE7")

(cons "·" "\U+00E3")(cons "Ï" "\U+1EBD")(cons "â" "\U+00F5")(cons "ò" "\U+0169")

(cons "¹" "\U+1EA1")(cons "Ñ" "\U+1EB9")(cons "ä" "\U+1ECD")(cons "ô" "\U+1EE5")

(cons "©" "\U+00E2")(cons "ª" "\U+00EA")(cons "«" "\U+00F4")(cons "­" "\U+01B0")

(cons "Ç" "\U+1EA7")(cons "Ò" "\U+1EC1")(cons "å" "\U+1ED3")(cons "õ" "\U+1EEB")

(cons "Ê" "\U+1EA5")(cons "Õ" "\U+1EBF")(cons "è" "\U+1ED1")(cons "ø" "\U+1EE9")

(cons "È" "\U+1EA9")(cons "Ó" "\U+1EC3")(cons "æ" "\U+1ED5")(cons "ö" "\U+1EED")

(cons "É" "\U+1EAB")(cons "Ô" "\U+1EC5")(cons "ç" "\U+1ED7")(cons "÷" "\U+1EEF")

(cons "Ë" "\U+1EAD")(cons "Ö" "\U+1EC7")(cons "é" "\U+1ED9")(cons "ù" "\U+1EF1")

(cons "¨" "\U+0103")(cons "×" "\U+00EC")(cons "¬" "\U+01A1")(cons "ú" "\U+1EF3")

(cons "»" "\U+1EB1")(cons "Ý" "\U+00ED")(cons "ê" "\U+1EDD")(cons "ý" "\U+00FD")

(cons "¾" "\U+1EAF")(cons "Ø" "\U+1EC9")(cons "í" "\U+1EDB")(cons "û" "\U+1EF7")

(cons "¼" "\U+1EB3")(cons "Ü" "\U+0129")(cons "ë" "\U+1EDF")(cons "ü" "\U+1EF9")

(cons "½" "\U+1EB5")(cons "Þ" "\U+1ECB")(cons "ì" "\U+1EE1")(cons "þ" "\U+1EF5")

(cons "Æ" "\U+1EB7")(cons "®" "\U+0111")(cons "î" "\U+1EE3")(cons "¦" "\U+01AF")

(cons "¢" "\U+00C2")(cons "§" "\U+0110")(cons "¤" "\U+00D4")(cons "¥" "\U+01A0")

(cons "¡" "\U+0102")(cons "£" "\U+00CA")))

(setq index 1 stdich "")

(repeat (strlen stsua)

(setq chuht (substr stsua index 1)

index (1+ index)

chusua (cond ((assoc chuht tapsua) (cdr (assoc chuht tapsua))) (t chuht))

stdich (strcat stdich chusua)))

stdich)))

(defun MakeLWPolyline (listpoint closed Linetype LTScale Layer Color xdata / Lst)

(setq Lst (list '(0 . "LWPOLYLINE")'(100 . "AcDbEntity")

(cons 8 (if Layer Layer (getvar "Clayer")))

(cons 6 (if Linetype Linetype "bylayer"))

(cons 48 (if LTScale LTScale 1))

(cons 62 (if Color Color 256))

'(100 . "AcDbPolyline")

(cons 90 (length listpoint))

(cons 70 (if closed 1 0))))

(foreach PP listpoint (setq Lst (append Lst (list (cons 10 PP)))))

(if xdata (setq Lst (append lst (list (cons -3 (list xdata))))))

(entmakex Lst));end

 

 

Em đang tham khảo lisp của bác Thaistreetz nhưng chưa ra ngô khoai gì. :))

 

 

32348161093_7653eb33d2_b.jpg

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 413509_adv_edv.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 ADV EDV để chạy lisp.

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

;;; Add vertext into Polyline and LWPolyline 2010 by Thaistreetz

(defun c:Adv (/ DKCV LST LSTPT N PL PL1 PLS PLSTLAST PT PTA WP)

(if (and (setq PL (car (entsel (TCVN3-Unicode " - Chän ®­êng Pline cÇn thªm ®Ønh ")))) (wcmatch (cdr (assoc 0 (entget PL))) "*POLYLINE"))

(progn

(vl-cmdf "undo" "begin")

(if (= (cdr (assoc 0 (entget PL))) "POLYLINE")

(progn

(setq DKCV T PLSTLAST (getvar "PLINETYPE"))

(setvar "PLINETYPE" 1)

(vl-cmdf "convert" "P" "S" PL "")

(setvar "PLINETYPE" PLSTLAST)

);progn

);if

(setq PLs (ssadd PL (ssadd)))

(while (progn

(sssetfirst nil PLs)

(initget 128 "u")

(setq PTa (getpoint (TCVN3-Unicode "\nPick ®Ønh cÇn thªm ")))

(if (= PTa "u") (progn (prompt "- Undo") (vl-cmdf "undo" "Back")) PTa))

(if (/= PTa "u")

(progn

(vl-cmdf "undo" "mark")

(setq PT (vlax-curve-getPointatParam PL (setq n (fix (vlax-curve-getParamatPoint PL (vlax-curve-getClosestPointto PL (setq PTa (trans PTa 1 0))))))))

(setq Lst nil)

(if (= n 0)

(progn

(setq Lstpt (reverse(acet-geom-pline-point-list PL nil))

PL1 (makeLWPolyline lstpt nil nil nil nil nil nil))

(if (= (fix (vlax-curve-getParamatPoint PL1 (vlax-curve-getClosestPointto PL1 PTa))) (- (length Lstpt) 1))

(mapcar '(lambda (x)

(setq Lst (if (equal x (list 10 (car PT) (cadr PT)) 0.0001)

(cons x (cons (list 10 (car PTa) (cadr PTa)) Lst))

(cons x Lst))))

(entget PL))

(mapcar '(lambda (x)

(setq Lst (if (equal x (list 10 (car PT) (cadr PT)) 0.0001)

(cons (list 10 (car PTa) (cadr PTa)) (cons x Lst))

(cons x Lst))))

(entget PL)))

(entdel PL1))

(mapcar '(lambda (x)

(setq Lst (if (equal x (list 10 (car PT) (cadr PT)) 0.0001)

(cons (list 10 (car PTa) (cadr PTa)) (cons x Lst))

(cons x Lst)))) (entget PL)))

(entmod (reverse Lst))))

);while

(sssetfirst)

(if DKCV (vl-cmdf "CONVERTPOLY" "H" wp "")))

(prompt (TCVN3-Unicode "\n§èi t­îng kh«ng ph¶i Polyline ")));if

(vl-cmdf "undo" "end")

(princ)

);end

;;; remove vertext into Polyline and LWPolyline

;;; copyright 2010 by Gia_Bach

;;; Edited 2010 by thaistreetz

(defun c:edv (/ removenth bulges coords ent idx param pt DKCV PLSTLAST)

(defun removenth (n lst / i rtn)

(setq i -1)

(foreach x lst (if (/= n (setq i (1+ i))) (setq rtn (cons x rtn))))

(reverse rtn))

(vl-cmdf "undo" "begin")

(while (progn

(initget 128 "u")

(setq ent (entsel (TCVN3-Unicode "\nChän ®Ønh Pline cÇn xãa: ")))

(if (= ent "u") (progn (prompt "- Undo") (vl-cmdf "undo" "Back")) ent))

(if (and (/= ent "u") (wcmatch (cdr (assoc 0 (entget (car ent)))) "*POLYLINE"))

(progn

(vl-cmdf "undo" "Mark")

(princ (setq pt (osnap (cadr ent) "near")))

(if (= (cdr (assoc 0 (entget (car ent)))) "POLYLINE")

(progn

(setq DKCV T PLSTLAST (getvar "PLINETYPE"))

(setvar "PLINETYPE" 1)

(vl-cmdf "convert" "P" "S" (car ent) "")

(setvar "PLINETYPE" PLSTLAST)))

(setq ent (vlax-ename->vla-object (car ent))

param (atoi (rtos (vlax-curve-getparamatpoint ent pt) 2 0))

coords (vlax-get ent 'coordinates) idx -1 bulges nil)

(repeat (/ (length coords) 2) (setq bulges (cons (vla-getbulge ent (setq idx (1+ idx))) bulges)))

(setq bulges (removenth param (reverse bulges)))

(repeat 2 (setq coords (removenth (* 2 param) coords)))

(vlax-put ent 'coordinates coords)

(setq idx -1)

(foreach bulge bulges (vla-setbulge ent (setq idx (1+ idx)) bulge))))

);while

(if DKCV (vl-cmdf "CONVERTPOLY" "H" ent ""))

(vl-cmdf "undo" "end")

(princ)

);end

(defun TCVN3-Unicode (stsua / index stdich chuht chusua tapsua)

(if (= (getvar "acadver") "16.1s (LMS Tech)") stsua (progn

(setq tapsua

(list (cons "µ" "\U+00E0")(cons "Ì" "\U+00E8")(cons "ß" "\U+00F2")(cons "ï" "\U+00F9")

(cons "¸" "\U+00E1")(cons "Ð" "\U+00E9")(cons "ã" "\U+00F3")(cons "ó" "\U+00FA")

(cons "¶" "\U+1EA3")(cons "Î" "\U+1EBB")(cons "á" "\U+1ECF")(cons "ñ" "\U+1EE7")

(cons "·" "\U+00E3")(cons "Ï" "\U+1EBD")(cons "â" "\U+00F5")(cons "ò" "\U+0169")

(cons "¹" "\U+1EA1")(cons "Ñ" "\U+1EB9")(cons "ä" "\U+1ECD")(cons "ô" "\U+1EE5")

(cons "©" "\U+00E2")(cons "ª" "\U+00EA")(cons "«" "\U+00F4")(cons "­" "\U+01B0")

(cons "Ç" "\U+1EA7")(cons "Ò" "\U+1EC1")(cons "å" "\U+1ED3")(cons "õ" "\U+1EEB")

(cons "Ê" "\U+1EA5")(cons "Õ" "\U+1EBF")(cons "è" "\U+1ED1")(cons "ø" "\U+1EE9")

(cons "È" "\U+1EA9")(cons "Ó" "\U+1EC3")(cons "æ" "\U+1ED5")(cons "ö" "\U+1EED")

(cons "É" "\U+1EAB")(cons "Ô" "\U+1EC5")(cons "ç" "\U+1ED7")(cons "÷" "\U+1EEF")

(cons "Ë" "\U+1EAD")(cons "Ö" "\U+1EC7")(cons "é" "\U+1ED9")(cons "ù" "\U+1EF1")

(cons "¨" "\U+0103")(cons "×" "\U+00EC")(cons "¬" "\U+01A1")(cons "ú" "\U+1EF3")

(cons "»" "\U+1EB1")(cons "Ý" "\U+00ED")(cons "ê" "\U+1EDD")(cons "ý" "\U+00FD")

(cons "¾" "\U+1EAF")(cons "Ø" "\U+1EC9")(cons "í" "\U+1EDB")(cons "û" "\U+1EF7")

(cons "¼" "\U+1EB3")(cons "Ü" "\U+0129")(cons "ë" "\U+1EDF")(cons "ü" "\U+1EF9")

(cons "½" "\U+1EB5")(cons "Þ" "\U+1ECB")(cons "ì" "\U+1EE1")(cons "þ" "\U+1EF5")

(cons "Æ" "\U+1EB7")(cons "®" "\U+0111")(cons "î" "\U+1EE3")(cons "¦" "\U+01AF")

(cons "¢" "\U+00C2")(cons "§" "\U+0110")(cons "¤" "\U+00D4")(cons "¥" "\U+01A0")

(cons "¡" "\U+0102")(cons "£" "\U+00CA")))

(setq index 1 stdich "")

(repeat (strlen stsua)

(setq chuht (substr stsua index 1)

index (1+ index)

chusua (cond ((assoc chuht tapsua) (cdr (assoc chuht tapsua))) (t chuht))

stdich (strcat stdich chusua)))

stdich)))

(defun MakeLWPolyline (listpoint closed Linetype LTScale Layer Color xdata / Lst)

(setq Lst (list '(0 . "LWPOLYLINE")'(100 . "AcDbEntity")

(cons 8 (if Layer Layer (getvar "Clayer")))

(cons 6 (if Linetype Linetype "bylayer"))

(cons 48 (if LTScale LTScale 1))

(cons 62 (if Color Color 256))

'(100 . "AcDbPolyline")

(cons 90 (length listpoint))

(cons 70 (if closed 1 0))))

(foreach PP listpoint (setq Lst (append Lst (list (cons 10 PP)))))

(if xdata (setq Lst (append lst (list (cons -3 (list xdata))))))

(entmakex Lst));end

Thảo luận gốc

Lisp được chia sẻ trong chủ đề Entmod Pline Theo Hình Dạng Của Pline Mẫu ( Vẫn Giữ Nguyên Entity Name). Xem đúng bài viết #413509 để đọc hướng dẫn và trao đổi thêm.

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