Lisp lệnh C2P trong chủ đề “Viết Lisp theo yêu cầu”
Chào các Mems, Tôi muốn có một đoạn lisp mà biến nhiều đoạn pline thành đúng một pline duy nhất.
Mong được giúp đỡ.
Thanks
Mình cũng đã tìm đến đoạn lisp của SSG, nhưng hình như nó không đúng ý mình (đã chạy thử)
Mong được giúp đỡ.
Thanks
Mình cũng đã tìm đến đoạn lisp của SSG, nhưng hình như nó không đúng ý mình (đã chạy thử)
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 31760_c2p.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 C2P để chạy lisp.
Mã nguồn 31760_c2p.lsp (trích từ bài viết gốc)
;;;***********************************************************
;;;CONVERT TO PLINES PROGRAM WITH FULL COMMENTS!
;;;Convert all objects: Line, Pline, Spline, Arc, Circle, Ellipse_
;;;to Plines. Length of 1 segment is specified by user
;;;Copy & Paste to Notepad, Saveas *.lsp, Appload then Type C2P to run
;;;Happy New Year 2008!
;;;Written by ssg - January 2008 - www.cadviet.com
;;;***********************************************************
;;;-------------------------------------------------------------
(defun makepl ( e d1 / ps pe d d2 p2);;;Make pline along curve e. Length of 1 segment = d1
(vl-load-com);;;Load Visual LISP extensions before use vlax-xxxx functions
(setq
ps (vlax-curve-getStartPoint e);;;Start point
pe (vlax-curve-getEndPoint e);;;End point
d (vlax-curve-getDistAtParam e (vlax-curve-getEndParam e));;;Length of curve e
d2 d1;;;Init variable distance
)
(command "pline");;;Call pline command
(command ps);;;Start point
(while (<= d2 d);;;While not over end point pe
(setq p2 (vlax-curve-getPointAtDist e d2));;;Variable point at d2 = length along curve
(command p2);;;Continue pline command from current point to p2
(setq d2 (+ d2 d1));;;Increase distance d2 by d1
);;;End while
(command pe "");;;Pline to pe and finish command
)
;;;-------------------------------------------------------------
(defun C:C2P( / d1 ss oldos i e ans);;;Convert to Plines
(if (not d0) (setq d0 0.5));;;Init dividual distance, global variable
(setq d1 (getreal (strcat "\nLength of 1 segment <" (rtos d0) ">:")));;;Input distance
(if d1 (setq d0 d1) (setq d1 d0));;;Reset or get distance
(setq
ss (ssget '((0 . "LINE,LWPOLYLINE,SPLINE,ARC,CIRCLE,ELLIPSE")));;;Selection set
oldos (getvar "osmode");;;Save osmode
i 0;;;Init counter
)
(setvar "osmode" 0);;;Disable osmode
(repeat (sslength ss);;;Repeat for all entities in ss
(setq e (ssname ss i));;;Set e for entity with ordinal i in selection set ss
(makepl e d1);;;Use makepl function. Make pline along e
(setq i (1+ i));;;Increase counter
)
(initget "Y N");;;Init keywords
(setq ans (getkword "\nDelete source objects? [Yes/No] :"));;;Get answer from user
(if (= ans "Y") (command "erase" ss ""));;;Erase source objects if ans = "y" or "Y"
(setvar "osmode" oldos);;;Reset osmode
(princ);;;Silent quit
)
;;;-------------------------------------------------------------Thảo luận gốc
Lisp được chia sẻ trong chủ đề Viết Lisp theo yêu cầu. Xem đúng bài viết #31760 để đọc hướng dẫn và trao đổi thêm.