kite15 Posted January 8, 2016 Share Posted January 8, 2016 (edited) Hi, I am trying to make a lisp code to filter the lines from a selection set. Requirement: Select only those line which having the provided length range as well as having angle vertical/horizontal (0, 90, 180, 270). Please help:unsure: Select Lines with in provided length range and zero angle(initget 7)(setq gh (getint "-->>Enter the gretar length:"))(setq lh (getint "-->>Enter the lower length:")) (setq s (ssadd)) (if (setq ss (ssget "_:L" '((0 . "LINE")))) (repeat (setq i (sslength ss)) (setq sn (ssname ss (setq i (1- i))) e (entget sn)) (setq l (distance (cdr (assoc 10 e)) (cdr (assoc 11 e)))) (setq ang (angle (cdr (assoc 10 e)) (cdr (assoc 11 e)))) (if (or (and (> l lh) (< l gh) (eq ang (* pi 0.))) ) (ssadd sn s) ) ) ) (sssetfirst nil s) (princ) )[/Code] Edited April 30, 2018 by SLW210 Code Tags Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 8, 2016 Share Posted January 8, 2016 (edited) Try something like this: (defun c:getlines ( / a e i m n p q s x ) (initget 6) (setq m (cond ((getdist "\nSpecify lower bound for length <none>: ")) (0.0))) (initget 6) (setq n (cond ((getdist "\nSpecify upper bound for length <none>: ")) (1e308))) (if (setq s (ssget "_X" (list '(0 . "LINE") (if (= 1 (getvar 'cvport)) (cons 410 (getvar 'ctab)) '(410 . "Model"))))) (repeat (setq i (sslength s)) (setq e (ssname s (setq i (1- i))) x (entget e) p (cdr (assoc 10 x)) q (cdr (assoc 11 x)) a (rem (angle p q) (/ pi 2.0)) ) (if (not (and (<= m (distance p q) n) (or (equal 0.0 a 1e-8) (equal (/ pi 2.0) a 1e-8)))) (ssdel e s) ) ) (princ "\nNo lines found in the current layout.") ) (sssetfirst nil s) (princ) ) Edited November 23, 2022 by Lee Mac Quote Link to comment Share on other sites More sharing options...
CADWORKER Posted April 30, 2018 Share Posted April 30, 2018 hi, lee, How about just an option for selecting the vertical or horizontal lines only. Quote Link to comment Share on other sites More sharing options...
ronjonp Posted April 30, 2018 Share Posted April 30, 2018 hi, lee, How about just an option for selecting the vertical or horizontal lines only. Try this: (defun c:foo (/ e s x) (if (setq s (ssget "_X" '((0 . "LINE")))) (foreach e (mapcar 'cadr (ssnamex s)) (setq a (mapcar '- (cdr (assoc 10 (setq x (entget e)))) (cdr (assoc 11 x)))) (and (not (or (equal 0.0 (car a) 1e- (equal 0.0 (cadr a) 1e-)) (ssdel e s)) ) (princ "\nNo lines found in drawing.") ) (sssetfirst nil s) (princ) ) Quote Link to comment Share on other sites More sharing options...
jberns Posted November 23, 2022 Share Posted November 23, 2022 On 4/30/2018 at 10:34 AM, ronjonp said: Try this: (defun c:foo (/ e s x) (if (setq s (ssget "_X" '((0 . "LINE")))) (foreach e (mapcar 'cadr (ssnamex s)) (setq a (mapcar '- (cdr (assoc 10 (setq x (entget e)))) (cdr (assoc 11 x)))) (and (not (or (equal 0.0 (car a) 1e- (equal 0.0 (cadr a) 1e-)) (ssdel e s)) ) (princ "\nNo lines found in drawing.") ) (sssetfirst nil s) (princ) ) I realize this is an old post, but should anyone try the code above they will discover missing parentheses. Quote Link to comment Share on other sites More sharing options...
jberns Posted November 23, 2022 Share Posted November 23, 2022 I repaired the code presented by @CADWORKER to resolve missing parentheses and a number format issue in the equal function. Please try this: (defun c:foo (/ a e s x) (if (setq s (ssget "_X" '((0 . "LINE")))) (foreach e (mapcar 'cadr (ssnamex s)) (setq a (mapcar '- (cdr (assoc 10 (setq x (entget e)))) (cdr (assoc 11 x)))) (if (and (not (or (equal 0.0 (car a) 1e-8) (equal 0.0 (cadr a) 1e-8)))) (ssdel e s) ) ;_if ) ;_foreach (princ "\nNo lines found in drawing.") ) ;_if (sssetfirst nil s) (princ) ) ;_ c:foo I hope it meets the intent. Regards, Jerry Quote Link to comment Share on other sites More sharing options...
ronjonp Posted November 23, 2022 Share Posted November 23, 2022 (edited) 1 hour ago, jberns said: I repaired the code presented by @CADWORKER to resolve missing parentheses and a number format issue in the equal function. Please try this: (defun c:foo (/ a e s x) (if (setq s (ssget "_X" '((0 . "LINE")))) (foreach e (mapcar 'cadr (ssnamex s)) (setq a (mapcar '- (cdr (assoc 10 (setq x (entget e)))) (cdr (assoc 11 x)))) (if (and (not (or (equal 0.0 (car a) 1e-8) (equal 0.0 (cadr a) 1e-8)))) (ssdel e s) ) ;_if ) ;_foreach (princ "\nNo lines found in drawing.") ) ;_if (sssetfirst nil s) (princ) ) ;_ c:foo I hope it meets the intent. Regards, Jerry I think the formatting got wonky with the forum update a few years ago: Edited November 23, 2022 by ronjonp Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted November 23, 2022 Share Posted November 23, 2022 I've updated my earlier post to correct the missing "8)" removed by the forum software change. Quote Link to comment Share on other sites More sharing options...
jberns Posted November 23, 2022 Share Posted November 23, 2022 @ronjonp / @Lee Mac, That would explain the troubles I had with the code. So when the forum changes in the future, we will be back to correct. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.