Tách lớp và lấy giao điểm trong cad 3D.
Hề hề hề,
Sau một hồi vọc vạch cái yêu cầu của bạn, mình làm thử cái này để bạn coi xem thế nào nhé. Hãy cố gắng test thử với nhiều loại khối đặc đặt ở các vị trí khác nhau xem nhé vì mình không co thời gian để test. Nhìn chung thì chắc nó sẽ có vài nhược điểm như mình đã nói ở bài trước, song nếu bạn chịu khó test thì sẽ tìm ra các lỗi và mới có thể khắc phục được. Mình chỉ làm hoàn toàn theo cảm tính và suy nghĩ cá nhân nên có thể không chuẩn mực như bạn cần được, bạn phải tự kiểm tra và nếu cần thì post lên chứ mình không thể hiểu hết mọi yêu cầu của bạn.
Hy vọng rằng nó sẽ giúp bạn được chút gì trong công việc của bạn
Chúc bạn vui và chóng thành tài nhé.
PS: cái này có sử dụng nguyên liệu chính của bác SSG, nếu bạn thấy ngon miệng thì đừng quên cám ơn bác ấy nhé.
- Tải lisp
- 185548_secor.lsp
Cách dùng
- Tải tệp 185548_secor.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 SECOR để chạy lisp.
Mã nguồn 185548_secor.lsp
;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/61092-nh%E1%BB%9D-vi%E1%BA%BFt-lispt%C3%A1ch-l%E1%BB%9Bp-v%C3%A0-l%E1%BA%A5y-giao-%C4%91i%E1%BB%83m-trong-cad-3d/
(defun c:secor (/ ent h ssl fn fw h0 h1 h d0 d1 e1 e2 e3 obj cen plst)
(setq ;;;;;;ssl (acet-ss-to-list (ssget))
fn (getfiled "Chon file de save" "" "txt" 1)
fw (open fn "w") )
(princ " Bang liet ke thuoc tinh co ban cua doi tuong \n " fw)
(vl-load-com)
(setq oldos (getvar "osmode"))
(setvar "osmode" 0)
(setq ent (car (entsel "\n Chon khoi can cat ")))
;;;(command "ucs" "ob" (getpoint "\n Chon diem goc tren be mat chuan"))
;;;(setq h (getreal "\n Nhap koang cach cao do mat cat: "))
(setq h0 (getreal "\n Nhap cao do bat dau cat: "))
(setq h1 (getreal "\n Nhap cao do ket thuc cat: "))
(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 h (+ h0 d1) i 1)
(while ( and (> h h0) (< h h1))
(command "undo" "be")
(command "section" ent "" "3points" (setq p1 (list 0 0 h)) (setq p2 (polar p1 0 100)) (setq p3 (polar p2 (* 0.5 pi) 50)))
(setq e1 (entlast))
(command "ucs" "ob" (getpoint "\n Chon diem goc tren mat cat"))
(command "move" e1 "" (setq p1 (getpoint "\n Chon diem goc")) (setq p2 (getpoint p1 "\n Chon diem dich")))
(setq obj (vlax-ename->vla-object e1))
(setq cen (vlax-safearray->list (vlax-variant-value (vlax-get-property obj 'Centroid))) )
(command "boundary" cen "" )
(setq e2 (entlast))
(command "move" e2 "" p2 p1)
(command "ucs" "w")
(makepl e2 d1)
(setq e3 (entlast))
(command "erase" e1 e2 "")
(setq plst (acet-geom-vertex-list e3))
(setq txt (strcat "LWPOLYLINE thu " (rtos i 2 0)))
(foreach pt plst
(setq txt (strcat txt "," (rtos (car pt) 2 4) " " (rtos (cadr pt) 2 4) " " (rtos h 2 4)))
)
(princ (strcat txt "\n") fw)
(setq i (1+ i))
(setq h (+ h0 (* i d1)))
(command "undo" "e")
)
(close fw)
(setvar "osmode" oldos)
(princ)
)
;;;-------------------------------------------------------------
(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
(if (not (equal pe ps 0.01))
(command pe "");;;Pline to pe and finish command
(command "c" )
)
)
;;;-------------------------------------------------------------
Thảo luận gốc
Lisp được chia sẻ trong chủ đề [Nhờ viết lisp]Tách lớp và lấy giao điểm trong cad 3D.. Xem đúng bài viết #185548 để đọc hướng dẫn và trao đổi thêm.