Lisp lệnh CUT trong chủ đề “Lệnh Trim CAD đặc biệt- làm thế nào để ấn phần dài cắt phần ngắn?”
........
Tiện đây nhờ các bác viết lisp minh họa bằng hình ảnh sau:
Hy vọng Lisp này đáp ứng được yêu cầu của "em" Hoằn.
(Chỉ sử dụng với Line và Arc)
(defun C:cut(/ ent ss e pt1 pt2 iPts)
(command "undo" "be")
(while
(not
(and
(setq ent (car (entsel "Duong chuan :")))
(if ent (wcmatch (cdr (assoc 0 (entget ent))) "LINE,ARC,RAY,XLINE" ) ) ) )
(princ "\nSelect Again: ") )
(setq ent (vlax-ename->vla-object ent))
(princ "\nVat bi cat...")
(if(setq ss (ssget "_:L" (list (cons 0 "LINE,ARC"))))
(foreach e (mapcar 'vlax-ename->vla-Object (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))))
(setq iPts (vlax-Invoke ent "IntersectWith" e 2)
ObjName (vla-get-ObjectName e)
pt1 (vlax-curve-getStartPoint e)
pt2 (vlax-curve-getEndPoint e))
(if (and iPts (= 3(length iPts) ))
(cond
((eq ObjName "AcDbLine") ;LINE
(if (> (distance iPts pt1)(distance iPts pt2))
(vla-put-EndPoint e (vlax-3d-point iPts))
(vla-put-StartPoint e (vlax-3d-point iPts)) ) )
((eq ObjName "AcDbArc") ;ARC
(setq center (vlax-safearray->list (variant-value (vla-get-Center e))))
(if (> (distance iPts pt1)(distance iPts pt2))
(vla-put-EndAngle e (vlax-make-variant(angle center iPts)) )
(vla-put-StartAngle e (vlax-make-variant(angle center iPts))) ) ) ))))
(command "undo" "e")(princ) )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 236205_cut.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 CUT để chạy lisp.
Mã nguồn 236205_cut.lsp (trích từ bài viết gốc)
(defun C:cut(/ ent ss e pt1 pt2 iPts)
(command "undo" "be")
(while
(not
(and
(setq ent (car (entsel "Duong chuan :")))
(if ent (wcmatch (cdr (assoc 0 (entget ent))) "LINE,ARC,RAY,XLINE" ) ) ) )
(princ "\nSelect Again: ") )
(setq ent (vlax-ename->vla-object ent))
(princ "\nVat bi cat...")
(if(setq ss (ssget "_:L" (list (cons 0 "LINE,ARC"))))
(foreach e (mapcar 'vlax-ename->vla-Object (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))))
(setq iPts (vlax-Invoke ent "IntersectWith" e 2)
ObjName (vla-get-ObjectName e)
pt1 (vlax-curve-getStartPoint e)
pt2 (vlax-curve-getEndPoint e))
(if (and iPts (= 3(length iPts) ))
(cond
((eq ObjName "AcDbLine") ;LINE
(if (> (distance iPts pt1)(distance iPts pt2))
(vla-put-EndPoint e (vlax-3d-point iPts))
(vla-put-StartPoint e (vlax-3d-point iPts)) ) )
((eq ObjName "AcDbArc") ;ARC
(setq center (vlax-safearray->list (variant-value (vla-get-Center e))))
(if (> (distance iPts pt1)(distance iPts pt2))
(vla-put-EndAngle e (vlax-make-variant(angle center iPts)) )
(vla-put-StartAngle e (vlax-make-variant(angle center iPts))) ) ) ))))
(command "undo" "e")(princ) )Thảo luận gốc
Lisp được chia sẻ trong chủ đề Lệnh Trim CAD đặc biệt- làm thế nào để ấn phần dài cắt phần ngắn?. Xem đúng bài viết #236205 để đọc hướng dẫn và trao đổi thêm.
