Jump to content

Select Lines by length and vertical and horizontal angle


Recommended Posts

Posted (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 by SLW210
Code Tags
Posted (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 by Lee Mac
  • 2 years later...
Posted

hi, lee,

 

How about just an option for selecting the vertical or horizontal lines only.

Posted
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)
)

  • 4 years later...
Posted
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.

Posted

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

Posted (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:
image.png.5161a98a52a23f7cef6085ab3a6983ad.png

Edited by ronjonp
Posted

I've updated my earlier post to correct the missing "8)" removed by the forum software change.

Posted

@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. 😉

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...