Jump to content

Lisp lệnh C2PL trong chủ đề “(Help) Xin lisp chuyển 2dpline,arc,ellipse thành pline”

Vào lúc 30/3/2020 tại 10:32, minhmani đã nói:

Hiện mình đang cần 1 lisp có thể chuyển tất cả các loại nét ( 2Dpline, arc, ellipse...) về thành pline. Mong các cao nhân của diễn đàn giúp đỡ. Xin cảm ơn :D

Năm 2009, Thiep có viết lisp này rồi, đã có trong thư viện lisp của cadviet, nhưng cũng chưa ưng ý lắm.

Lisp sau đây Thiep đã hoàn thiện nó, các curve có đoạn bán kính cong lớn thì node sẽ thưa hơn những đoạn có bán kính cong nhỏ.

TB: Xin hỏi minhmani, bản vẽ của bạn dùng phần mềm gì mà bạn có thể vẽ được mặt cắt địa chất công trình như vậy, và dữ liệu đầu vào như thế nào? Có thể share cho mình được không, để học hỏi thêm. (mail: [email protected])

(defun DXF (code en) (cdr (assoc code (entget en))))
(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)
    )
)
(defun c:c2pl (/ ss lstpo obj)
    (command "undo" "be")
    (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))
                 (Vla-put-color obj (dxf 62 x))
                 (entdel x)
             )
            (acet-ss-to-list ss)
    )
    (acet-error-restore)
    (command "undo" "en")
    (princ "\nOk")
)

 

Cách dùng

  1. Tải tệp 445225_c2pl.lsp về máy.
  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 C2PL để chạy lisp.

Mã nguồn 445225_c2pl.lsp

;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/180111-help-xin-lisp-chuy%E1%BB%83n-2dplinearcellipse-th%C3%A0nh-pline/
(defun DXF (code en) (cdr (assoc code (entget en))))
(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)
    )
)
(defun c:c2pl (/ ss lstpo obj)
    (command "undo" "be")
    (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))
                 (Vla-put-color obj (dxf 62 x))
                 (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ủ đề (Help) Xin lisp chuyển 2dpline,arc,ellipse thành pline. Xem đúng bài viết #445225 để đọc hướng dẫn và trao đổi thêm.

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