Nhờ tiền bối viết giùm lisp chuyển hình tròn thành đa giác
46 phút trước, hawking312 đã nói:Như tiêu đề ạ, em có việc muốn chuyển các đường cong hoặc hình tròn thành các đa giác. Em thấy có app tương tự của Autodesk nhưng có tính phí, mong các tiền bối giúp đỡ.
Link Autodesk:
CIR2VECT – Circle to Vectored polygonARCVECT – Arc, PolyArc and Circle Vectorizer
Video ví dụ
Lisp này mình mới vừa đăng cách nay gần 1 tháng, chịu khó tìm là có:
;;; lisp convert curve: ARC, CIRCLE, ELLIPSE, SPLINE to Lwpolyline
;;; by Trân Thiêp 0918841230
(defun DXF (code en) (cdr (assoc code (entget en))))
(defun c:c2pl (/ ss lstpo obj)
(command "undo" "be")
(and (not ACET-GEOM-SPLINE-POINT-LIST)
(findfile "acetutil.arx")
(arxload (findfile "acetutil.arx") "Failed to Load Express Tools")
)
(defun curve->Lstpo (ent num / LL_UR)
(setq LL_UR (acet-ent-geomextents ent))
(ACET-GEOM-SPLINE-POINT-LIST ent
(/ (distance (car LL_UR) (cadr LL_UR)) num)
)
)
(acet-error-init '(("cmdecho" 0 "osmode" 0 "PLINEGEN" 1) 1 (acet-ui-status)))
(acet-ui-status "\nSelect curves to convert it into Lwpolylines" "PROMPT")
(while (NOT (setq ss (ssget '((0 . "ARC,CIRCLE,ELLIPSE,SPLINE")))))
(acet-ui-status "\nSelect arn't right, please select curves again" "PROMPT")
)
(acet-ui-status)
(mapcar '(lambda (x)
(cond ((wcmatch (acet-dxf 0 (entget x)) "ARC,CIRCLE,ELLIPSE")
(acet-Lwpline-make (list (curve->Lstpo x 2020)))
)
(T (acet-Lwpline-make (list (curve->Lstpo x 3000))))
)
(setq obj (vlax-ename->vla-object (entlast)))
(if (dxf 6 x)(Vla-put-Linetype obj (dxf 6 x)))
(if (dxf 48 x)
(Vla-put-LinetypeScale obj (dxf 48 x))
)
(Vla-put-LinetypeGeneration obj :vlax-true)
(Vla-put-layer obj (dxf 8 x))
(if (setq col (dxf 62 x))
(Vla-put-color obj col)
(Vla-put-color obj 256)
)
(entdel x)
)
(acet-ss-to-list ss)
)
(acet-error-restore)
(command "undo" "en")
(princ "\nOk")
)
- Tải lisp
- 446953_c2pl.lsp
Cách dùng
- Tải tệp 446953_c2pl.lsp về máy.
- 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 C2PL để chạy lisp.
Mã nguồn 446953_c2pl.lsp
;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/181508-y%C3%AAu-c%E1%BA%A7u-nh%E1%BB%9D-ti%E1%BB%81n-b%E1%BB%91i-vi%E1%BA%BFt-gi%C3%B9m-lisp-chuy%E1%BB%83n-h%C3%ACnh-tr%C3%B2n-th%C3%A0nh-%C4%91a-gi%C3%A1c/
;;; lisp convert curve: ARC, CIRCLE, ELLIPSE, SPLINE to Lwpolyline
;;; by Trân Thiêp 0918841230
(defun DXF (code en) (cdr (assoc code (entget en))))
(defun c:c2pl (/ ss lstpo obj)
(command "undo" "be")
(and (not ACET-GEOM-SPLINE-POINT-LIST)
(findfile "acetutil.arx")
(arxload (findfile "acetutil.arx") "Failed to Load Express Tools")
)
(defun curve->Lstpo (ent num / LL_UR)
(setq LL_UR (acet-ent-geomextents ent))
(ACET-GEOM-SPLINE-POINT-LIST ent
(/ (distance (car LL_UR) (cadr LL_UR)) num)
)
)
(acet-error-init '(("cmdecho" 0 "osmode" 0 "PLINEGEN" 1) 1 (acet-ui-status)))
(acet-ui-status "\nSelect curves to convert it into Lwpolylines" "PROMPT")
(while (NOT (setq ss (ssget '((0 . "ARC,CIRCLE,ELLIPSE,SPLINE")))))
(acet-ui-status "\nSelect arn't right, please select curves again" "PROMPT")
)
(acet-ui-status)
(mapcar '(lambda (x)
(cond ((wcmatch (acet-dxf 0 (entget x)) "ARC,CIRCLE,ELLIPSE")
(acet-Lwpline-make (list (curve->Lstpo x 2020)))
)
(T (acet-Lwpline-make (list (curve->Lstpo x 3000))))
)
(setq obj (vlax-ename->vla-object (entlast)))
(if (dxf 6 x)(Vla-put-Linetype obj (dxf 6 x)))
(if (dxf 48 x)
(Vla-put-LinetypeScale obj (dxf 48 x))
)
(Vla-put-LinetypeGeneration obj :vlax-true)
(Vla-put-layer obj (dxf 8 x))
(if (setq col (dxf 62 x))
(Vla-put-color obj col)
(Vla-put-color obj 256)
)
(entdel x)
)
(acet-ss-to-list ss)
)
(acet-error-restore)
(command "undo" "en")
(princ "\nOk")
)Thảo luận gốc
Lisp được chia sẻ trong chủ đề [Yêu cầu] Nhờ tiền bối viết giùm lisp chuyển hình tròn thành đa giác. Xem đúng bài viết #446953 để đọc hướng dẫn và trao đổi thêm.