Could anyone here help me by adding additional lines on the below code that when press ESCAPE it will cancel or undo the program. Currently, when I press escape it will stop on the middle of the program and I need to press ctrl+Z to back on the beginning.
@pbejse This is your code Twisty.lsp and I'm seeking to add ESCAPE function to cancel the program like most of the program do.
(Defun c:Twisty ( / _sort rotate_about_point _FollowThePlate _Looper
mxv e ent obj ap stretchy pbox gr data code)
;; pBe Feb 2021 | Rotate with stretch ;;
(defun rotate_about_point ( p b a )
;; pBe | LeeMAc 2021 ;;
( (lambda ( m ) (mapcar '+ (mxv m p) (mapcar '- b (mxv m b))))
(list
(list (cos a) (- (sin a)))
(list (sin a) (cos a))
)
)
)
(defun _FollowThePlate (l a / ev nsp nwp sp_ep)
(mapcar '(lambda (j)
(setq ev (car j) sp_ep (cadr j))
(Setq nsp (trans (rotate_about_point (Car sp_ep) ap a) 1 0))
(Vlax-put ev 'Coordinates
(append (list (Car nsp)(cadr nsp)) (cadr sp_eP)))
(list ev (list nsp (Cadr sp_ep))))
l
)
)
(defun _Looper (selset U_ang m )
(redraw)
(foreach itm
(mapcar 'vlax-ename->vla-object
(vl-remove-if 'listp (mapcar 'cadr (ssnamex selset)))
)
(Vlax-invoke itm 'Rotate ap (- U_ang ang))
)
(setq stretchy (_FollowThePlate stretchy (- U_ang ang)))
(setq ang U_ang)
(and m (grdraw ap data 1))
(setq n (/ (* ang 180.0) pi))
(princ (strcat "\nCurrent angle <Rotation/Any key to end>: "
(rtos (if (>= n 180) (- n 360) n) 2 0)))
m
)
;; Matrix x Vector - Vladimir Nesterovsky
;; Args: m - nxn matrix, v - vector in R^n
(defun mxv ( m v )
(mapcar '(lambda ( r ) (apply '+ (mapcar '* r v))) m)
)
(setq _sort (lambda (l s)
(vl-sort l '(lambda (a b)(s (car a)(car b))))))
(if (setq stretchy nil pBox nil gss (ssadd) ss (ssget "_:L" ))
(progn
(repeat (setq i (sslength ss))
(setq e (ssname ss (setq i (1- i)))
ent (entget e)
obj (cdr (assoc 0 ent))
)
(cond
((and (eq "LWPOLYLINE" obj)
(setq pts (mapcar 'cdr
(vl-remove-if-not
'(lambda (d) (= (Car d) 10))
ent
)
)
)
(= (length pts) 2)
)
(setq stretchy
(cons (list (vlax-ename->vla-object e) pts)
stretchy
)
)(ssdel e ss)
)
((eq "LWPOLYLINE" obj)
(setq Pbox (cons (list (vlax-curve-getarea e) e
(mapcar (function (lambda (a b) (* (+ a b) 0.5))) (car pts)(caddr pts)))
Pbox))
)
)
)
(setq ap (append (caddar (_sort Pbox >)) '(0.0)) ang 0.0)
(setq stretchy (mapcar '(lambda (w)
(list (Car w) (mapcar 'cadr
(_sort (mapcar '(lambda (m)
(list (distance ap m) m)) (cadr w)) <)))) stretchy))
(while
(progn
(setq gr (grread t 15 0)
code (car gr)
data (cadr gr)
)
(cond
((= 5 code)
(_looper ss (angle ap (cadr gr)) t)
)
((and (= 2 code) (member data '(82 114)))
(redraw)
(initget 7)
(setq U_angle (getangle " R\nEnter Angle: "))
(_looper ss U_angle nil)
)
((or (= 3 code) (= 2 code))
(redraw)
)
)
)
)
)
)(princ)
)