Jump to content

Lỗi Lisp Vẽ Wipeout Không Có Tác Dụng Trong Acad2016

Sửa lại và test trên AC2015 ok.

(defun c:OB2WO (/ ent lst nor ss)
  (vl-load-com)
  (if (setq ss (ssget (list (cons 0 "CIRCLE,ELLIPSE,LWPOLYLINE")))) 
   (progn (vla-StartundoMark (vla-get-ActiveDocument (vlax-get-acad-object)))
     (initget "Yes No") 
     (setq ans (getkword "\nDelete source object? [Yes/No] <No>: ")) 
    (foreach ent (ST:Ss->ListEnt ss)
     (setq lst (ent2ptlst ent))
     (setq nor (cdr (assoc 210 (entget ent)))) 
     (makeWipeout lst nor)
     (if (or (not ans) (wcmatch (strcase ans) "YES"))(entdel ent))
    )
    (vla-EndundoMark (vla-get-ActiveDocument (vlax-get-acad-object)))
   )
  )
 )
 
 (defun c:wof (/ elst)
  (cond ((and (setq elst (dictsearch (namedobjdict) "ACAD_WIPEOUT_VARS"))
(ssget "x" '((0 . "WIPEOUT,INSERT"))) )
(entmod (subst (cons 70 (boole 6 (cdr (assoc 70 elst)) 1)) (assoc 70 elst) elst))
 (vlax-for obj (vla-get-activeselectionset (vla-get-activedocument (vlax-get-acad-object))) (vla-update obj) ) )
    (T (princ "\nHave no wipeout object !"))
  )
  (princ)
 )
 
 (defun c:wo2pl (/ ss n wo elst pts norm ans)
 (if (setq ss (ssget '((0 . "WIPEOUT"))))
 (progn (initget "Yes No") 
  (setq ans (getkword "\nDelete source object? [Yes/No] <No>: ")) 
  (foreach wo (ST:Ss->ListEnt ss) 
   (setq elst (entget wo)
    norm (vunit (v^v (cdr (assoc 11 elst)) (cdr (assoc 12 elst))))
    pts (wipeout2plst wo)
   )
   (entmake (append (list '(0 . "LWPOLYLINE") '(100 . "AcDbEntity") '(100 . "AcDbPolyline")
(cons 90 (length pts)) (cons 38 (caddr (trans (car pts) 0 norm))) '(70 . 1) (cons 210 norm) )
(mapcar '(lambda (pt) (setq pt (trans pt 0 norm)) (list 10 (car pt) (cadr pt)) ) pts ) )
   )
   (if (or (not ans) (wcmatch (strcase ans) "YES"))(entdel wo))
(princ) 
 ))) 
 )
 
 (defun wipeout2plst (wo / elst u v mat)
  (setq elst (entget wo)
  u (cdr (assoc 11 elst))
  v (cdr (assoc 12 elst))
  mat (list u (mapcar '- v) '(0. 0. 1.))
  )
  (mapcar '(lambda (p) (mapcar '+ (mxv (trp mat) p) (mapcar '(lambda (x y) (/ (+ x y) 2.)) u v) (cdr (assoc 10 elst)) ) )
   (cdr (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 14)) elst) )))
 )
 
 (defun trp (m) (apply 'mapcar (cons 'list m)))
 (defun mxv (m v)  (mapcar '(lambda (r) (apply '+ (mapcar '* r v))) m))
 (defun v^v (v1 v2)
  (list (- (* (cadr v1) (caddr v2)) (* (caddr v1) (cadr v2)))
   (- (* (caddr v1) (car v2)) (* (car v1) (caddr v2)))
   (- (* (car v1) (cadr v2)) (* (cadr v1) (car v2)))
  )
 )
 
 (defun vunit (v)
  ((lambda (l) (if (/= 0 l) (mapcar (function (lambda (x) (/ x l))) v) ) )
   (distance '(0 0 0) v)
  )
 )
 
 (defun ent2ptlst (ent / obj dist n lst p_lst prec)
  (vl-load-com)
  (if (= (type ent) 'ENAME)  (setq obj (vlax-ename->vla-object ent)))
  (cond ((member (cdr (assoc 0 (entget ent))) '("CIRCLE" "ELLIPSE"))
(setq dist (/ (vlax-curve-getDistAtParam obj (vlax-curve-getEndParam obj) ) 50 ) n 0 )
(repeat 50 (setq lst (cons (trans (vlax-curve-getPointAtDist obj (* dist (setq n (1+ n)))) 0 (vlax-get obj 'Normal)) lst ))))
 
   (T (setq p_lst (vl-remove-if-not '(lambda (x) (or (= (car x) 10) (= (car x) 42) ) ) (entget ent) ) )
(while p_lst (setq lst (cons (append (cdr (assoc 10 p_lst)) (list (cdr (assoc 38 (entget ent)))) ) lst ) )
(if (/= 0 (cdadr p_lst))
(progn
(setq prec (1+ (fix (* 25 (sqrt (abs (cdadr p_lst))))))
dist (/ (- (if (cdaddr p_lst) (vlax-curve-getDistAtPoint obj (trans (cdaddr p_lst) ent 0) )
(vlax-curve-getDistAtParam obj (vlax-curve-getEndParam obj) ) )
(vlax-curve-getDistAtPoint obj (trans (cdar p_lst) ent 0) ) ) prec ) n 0 )
   (repeat (1- prec)
    (setq lst (cons (trans (vlax-curve-getPointAtDist obj (+ (vlax-curve-getDistAtPoint obj (trans (cdar p_lst) ent 0) )
(* dist (setq n (1+ n))) ) ) 0 ent ) lst ) ))
  )
   )
   (setq p_lst (cddr p_lst))
  )
  )
  )
  lst
)
  (defun MakeWipeout (pt_lst nor / dxf10 max_dist cen dxf_14)
 (setq dxf10 (list (apply 'min (mapcar 'car pt_lst)) (apply 'min (mapcar 'cadr pt_lst)) (caddar pt_lst)))
 (setq max_dist (float (apply 'max (mapcar '- (apply 'mapcar (cons 'max pt_lst)) dxf10))))
 (setq cen (mapcar '+ dxf10 (list (/ max_dist 2) (/ max_dist 2) 0.0)))
 (setq dxf14 (mapcar '(lambda (p) (mapcar '/ (mapcar '- p cen) (list max_dist (- max_dist) 1.0))) pt_lst))
 (setq dxf14 (reverse (cons (car dxf14) (reverse dxf14))))
    (entmake (append (list '(0 . "WIPEOUT") '(100 . "AcDbEntity") '(100 . "AcDbWipeout")
(cons 10 (trans dxf10 nor 0)) (cons 11 (trans (list max_dist 0.0 0.0) nor 0))
(cons 12 (trans (list 0.0 max_dist 0.0) nor 0)) '(13 1.0 1.0 0.0)
'(70 . 7) '(280 . 1) '(281 . 50) '(282 . 50) '(283 . 0)
'(71 . 2) (cons 91 (length dxf14)) )
(mapcar '(lambda (p) (cons 14 p)) dxf14) )
   )
 )
 
 (defun ST:Ss->ListEnt (ss / n e l)
 (setq n (sslength ss))
 (while (setq e (ssname ss (setq n (1- n))))
  (setq l (cons e l))
 ) 
 ) 

Cách dùng

  1. Tải tệp 403997_ob2wo_wof_wo2pl.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 OB2WO WOF WO2PL để chạy lisp.

Mã nguồn 403997_ob2wo_wof_wo2pl.lsp

;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/164361-h%E1%BB%8Fi-l%E1%BB%97i-lisp-v%E1%BA%BD-wipeout-kh%C3%B4ng-c%C3%B3-t%C3%A1c-d%E1%BB%A5ng-trong-acad2016/
(defun c:OB2WO (/ ent lst nor ss)
  (vl-load-com)
  (if (setq ss (ssget (list (cons 0 "CIRCLE,ELLIPSE,LWPOLYLINE")))) 
   (progn (vla-StartundoMark (vla-get-ActiveDocument (vlax-get-acad-object)))
     (initget "Yes No") 
     (setq ans (getkword "\nDelete source object? [Yes/No] <No>: ")) 
    (foreach ent (ST:Ss->ListEnt ss)
     (setq lst (ent2ptlst ent))
     (setq nor (cdr (assoc 210 (entget ent)))) 
     (makeWipeout lst nor)
     (if (or (not ans) (wcmatch (strcase ans) "YES"))(entdel ent))
    )
    (vla-EndundoMark (vla-get-ActiveDocument (vlax-get-acad-object)))
   )
  )
 )
 
 (defun c:wof (/ elst)
  (cond ((and (setq elst (dictsearch (namedobjdict) "ACAD_WIPEOUT_VARS"))
(ssget "x" '((0 . "WIPEOUT,INSERT"))) )
(entmod (subst (cons 70 (boole 6 (cdr (assoc 70 elst)) 1)) (assoc 70 elst) elst))
 (vlax-for obj (vla-get-activeselectionset (vla-get-activedocument (vlax-get-acad-object))) (vla-update obj) ) )
    (T (princ "\nHave no wipeout object !"))
  )
  (princ)
 )
 
 (defun c:wo2pl (/ ss n wo elst pts norm ans)
 (if (setq ss (ssget '((0 . "WIPEOUT"))))
 (progn (initget "Yes No") 
  (setq ans (getkword "\nDelete source object? [Yes/No] <No>: ")) 
  (foreach wo (ST:Ss->ListEnt ss) 
   (setq elst (entget wo)
    norm (vunit (v^v (cdr (assoc 11 elst)) (cdr (assoc 12 elst))))
    pts (wipeout2plst wo)
   )
   (entmake (append (list '(0 . "LWPOLYLINE") '(100 . "AcDbEntity") '(100 . "AcDbPolyline")
(cons 90 (length pts)) (cons 38 (caddr (trans (car pts) 0 norm))) '(70 . 1) (cons 210 norm) )
(mapcar '(lambda (pt) (setq pt (trans pt 0 norm)) (list 10 (car pt) (cadr pt)) ) pts ) )
   )
   (if (or (not ans) (wcmatch (strcase ans) "YES"))(entdel wo))
(princ) 
 ))) 
 )
 
 (defun wipeout2plst (wo / elst u v mat)
  (setq elst (entget wo)
  u (cdr (assoc 11 elst))
  v (cdr (assoc 12 elst))
  mat (list u (mapcar '- v) '(0. 0. 1.))
  )
  (mapcar '(lambda (p) (mapcar '+ (mxv (trp mat) p) (mapcar '(lambda (x y) (/ (+ x y) 2.)) u v) (cdr (assoc 10 elst)) ) )
   (cdr (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 14)) elst) )))
 )
 
 (defun trp (m) (apply 'mapcar (cons 'list m)))
 (defun mxv (m v)  (mapcar '(lambda (r) (apply '+ (mapcar '* r v))) m))
 (defun v^v (v1 v2)
  (list (- (* (cadr v1) (caddr v2)) (* (caddr v1) (cadr v2)))
   (- (* (caddr v1) (car v2)) (* (car v1) (caddr v2)))
   (- (* (car v1) (cadr v2)) (* (cadr v1) (car v2)))
  )
 )
 
 (defun vunit (v)
  ((lambda (l) (if (/= 0 l) (mapcar (function (lambda (x) (/ x l))) v) ) )
   (distance '(0 0 0) v)
  )
 )
 
 (defun ent2ptlst (ent / obj dist n lst p_lst prec)
  (vl-load-com)
  (if (= (type ent) 'ENAME)  (setq obj (vlax-ename->vla-object ent)))
  (cond ((member (cdr (assoc 0 (entget ent))) '("CIRCLE" "ELLIPSE"))
(setq dist (/ (vlax-curve-getDistAtParam obj (vlax-curve-getEndParam obj) ) 50 ) n 0 )
(repeat 50 (setq lst (cons (trans (vlax-curve-getPointAtDist obj (* dist (setq n (1+ n)))) 0 (vlax-get obj 'Normal)) lst ))))
 
   (T (setq p_lst (vl-remove-if-not '(lambda (x) (or (= (car x) 10) (= (car x) 42) ) ) (entget ent) ) )
(while p_lst (setq lst (cons (append (cdr (assoc 10 p_lst)) (list (cdr (assoc 38 (entget ent)))) ) lst ) )
(if (/= 0 (cdadr p_lst))
(progn
(setq prec (1+ (fix (* 25 (sqrt (abs (cdadr p_lst))))))
dist (/ (- (if (cdaddr p_lst) (vlax-curve-getDistAtPoint obj (trans (cdaddr p_lst) ent 0) )
(vlax-curve-getDistAtParam obj (vlax-curve-getEndParam obj) ) )
(vlax-curve-getDistAtPoint obj (trans (cdar p_lst) ent 0) ) ) prec ) n 0 )
   (repeat (1- prec)
    (setq lst (cons (trans (vlax-curve-getPointAtDist obj (+ (vlax-curve-getDistAtPoint obj (trans (cdar p_lst) ent 0) )
(* dist (setq n (1+ n))) ) ) 0 ent ) lst ) ))
  )
   )
   (setq p_lst (cddr p_lst))
  )
  )
  )
  lst
)
  (defun MakeWipeout (pt_lst nor / dxf10 max_dist cen dxf_14)
 (setq dxf10 (list (apply 'min (mapcar 'car pt_lst)) (apply 'min (mapcar 'cadr pt_lst)) (caddar pt_lst)))
 (setq max_dist (float (apply 'max (mapcar '- (apply 'mapcar (cons 'max pt_lst)) dxf10))))
 (setq cen (mapcar '+ dxf10 (list (/ max_dist 2) (/ max_dist 2) 0.0)))
 (setq dxf14 (mapcar '(lambda (p) (mapcar '/ (mapcar '- p cen) (list max_dist (- max_dist) 1.0))) pt_lst))
 (setq dxf14 (reverse (cons (car dxf14) (reverse dxf14))))
    (entmake (append (list '(0 . "WIPEOUT") '(100 . "AcDbEntity") '(100 . "AcDbWipeout")
(cons 10 (trans dxf10 nor 0)) (cons 11 (trans (list max_dist 0.0 0.0) nor 0))
(cons 12 (trans (list 0.0 max_dist 0.0) nor 0)) '(13 1.0 1.0 0.0)
'(70 . 7) '(280 . 1) '(281 . 50) '(282 . 50) '(283 . 0)
'(71 . 2) (cons 91 (length dxf14)) )
(mapcar '(lambda (p) (cons 14 p)) dxf14) )
   )
 )
 
 (defun ST:Ss->ListEnt (ss / n e l)
 (setq n (sslength ss))
 (while (setq e (ssname ss (setq n (1- n))))
  (setq l (cons e l))
 ) 
 ) 

Thảo luận gốc

Lisp được chia sẻ trong chủ đề [ Hỏi ] Lỗi Lisp Vẽ Wipeout Không Có Tác Dụng Trong Acad2016. Xem đúng bài viết #403997 để đọc hướng dẫn và trao đổi thêm.

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