- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello guys,
I have this routine thanks to the great work of BeekeeCZ
https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/erase-all-but/m-p/5926425
It will delete all objects outside specific rectangles. I made small modifications to fit my needs and everything works great 99% of the time.
(defun c:EOUT (/ spol sall sint i n e) (if (and (setq spol (ssget "_X" '((0 . "LWPOLYLINE") (410 . "Model") (-4 . "<OR") (8 . "Tx-Viewport") (8 . "Tx-Contour") (-4 . "OR>")))) (setq sall (ssget "_X" '((0 . "~IMAGE") (410 . "Model") (-4 . "<AND") (-4 . "<NOT") (-4 . "<OR") (8 . "Tx-Viewport") (8 . "Tx-Contour") (-4 . "OR>") (-4 . "NOT>") (-4 . "AND>")))) );and (progn (setq i -1) (repeat (setq i (sslength spol)) (setq sint (ssget "_CP" (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget (ssname spol (setq i (1- i)))))))) (repeat (setq n (sslength sint)) (if (ssmemb (setq e (ssname sint (setq n (1- n)))) sall) (ssdel e sall) );if );repeat );repeat );progn );if (if sall (command "_.ERASE" sall "") );if )
From time to time, something inexplicable happens and the routine crashes.
In my tests, the SSGET with CP gets an error in the LAMBDA that I do not understand. Maybe the file is corrupt or something. I attached two files, one that works and one that does not.
So my goal is to capture this error with a "vl-catch-all-apply" to avoid erase if the error occurs. But obviously I'm not having success. Could someone please help me?
This is what I get so far:
(defun c:EOUT (/ spol sall sint i n e errobj) (if (and (setq spol (ssget "_X" '((0 . "LWPOLYLINE") (410 . "Model") (-4 . "<OR") (8 . "Tx-Viewport") (8 . "Tx-Contour") (-4 . "OR>")))) (setq sall (ssget "_X" '((0 . "~IMAGE") (410 . "Model") (-4 . "<AND") (-4 . "<NOT") (-4 . "<OR") (8 . "Tx-Viewport") (8 . "Tx-Contour") (-4 . "OR>") (-4 . "NOT>") (-4 . "AND>")))) );and (progn (setq i -1) (repeat (setq i (sslength spol)) (setq sint (ssget "_CP" (mapcar 'cdr (vl-remove-if-not (setq errobj (vl-catch-all-apply '(lambda (x) (= (car x) 10)) (entget (ssname spol (setq i (1- i)))))))))) (if (vl-catch-all-error-p errobj) (print (strcat "An error occurred: " (vl-catch-all-error-message errobj))) (repeat (setq n (sslength sint)) (if (ssmemb (setq e (ssname sint (setq n (1- n)))) sall) (ssdel e sall) );if );repeat );if );repeat );progn );if (if (and sall (null errobj)) (command "_.ERASE" sall "") );if );defun
Thanks,
Marcelo
Solved! Go to Solution.