Jump to content

LISP for Selection of alternate lines from the selection set of lines like 1st, 3rd, 5th, .....etc lines in autocad.


Pranesh Rathinam

Recommended Posts

Hello guys,
I am new to this forum.

I need LISP for Selection of alternate lines from the selection set of lines like 1st, 3rd, 5th, .....etc lines in Autocad.
I am attaching the file with my requirement.
 

Alternate Selection of lines.dwg

 

Please help me out with an possible lisp solution.
Also,
Is there a Autocad Plugin to do this?
If so Please share the link 

Thanks in advance,
Pranesh Rathinam

Link to comment
Share on other sites

(defun c:t1 ( / ss l mid-pt ss->el)
  (defun mid-pt (e / x)
    (setq x (entget e))(mapcar '* (mapcar '+ (cdr (assoc 10 x)) (cdr (assoc 11 x))) '(0.5 0.5 0.5)))
  (defun ss->el (ss / i l)
    (setq i 0)(repeat (sslength ss)(setq l (cons (ssname ss i) l) i (1+ i))) l)
  (if (setq ss (ssget (list (cons 0 "Line"))))
    (setq l (vl-sort (ss->el ss) '(lambda (a b) (< (cadr (mid-pt a)) (cadr (mid-pt b)))))))
  (setq ss (ssadd) i -2)
  (while (setq e (nth (setq i (+ i 2)) l))(ssadd e ss))
  (command "chprop" ss "" "color" "red" "")
)

 

load code , start with t1 or (c:t1) , select the lines with window or crossing (no problem selecting the leaders also because they are filtered out anyway so don't worry , be happy) et voila...

image.png.8f6983c24cf76fc91bbc9188427c00f8.png

Edited by rlx
add comments on how to use
  • Like 3
Link to comment
Share on other sites

If lines all have same Y midpoint, vertical lines then the sort may not get correct order maybe a sort X&Y car & cadr.

(setq l (vl-sort (ss->el ss)
	 '(lambda (a b)
	    (cond
	      ((< (car (mid-pt a)) (car (mid-pt b))))
	      ((= (car (mid-pt a)) (car (mid-pt b))) (< (cadr (mid-pt a)) (cadr (mid-pt b))))
	    )
	  )
)
)

 

 

 

Link to comment
Share on other sites

Thank you rlx & BIGAL for your valuable replies.

Now it is possible to select alternate line using quick select after the coloring happens to red with the help of the above lisp.
I have achieved my need thank you so much

Also Please do help me with gaining a small clarity about the same LISP,

  1. Is this LISP can be made/modified to select lines at the end of the LISP execution(As the result out of 150 lines 75 lines alternatively at the end of the LISP execution without changing the color)?
  2. Is there any option to control which alternate lines to get selected (I mean 1st, 2nd, 3rd,...... or 2nd,4th,6th,.....) can an option can be set for this in above same LISP?
Link to comment
Share on other sites

Ok good time to start to learn lisp and the way some things work.

 

This sets 2 variables (setq ss (ssadd) i -2) so the ss is a blank selection and i is set to -2

(nth (setq i (+ i 2)) l)) this gets a item from the sorted points l, to get the 1st item in a list of points it is referenced as starting at zero 0, so if i =-2 then (setq i (+ i 2)) = 0 next will be items (nth 2 4 6 etc so if want even lines (setq ss (ssadd) i -1) this will result in (nth 1 3 5 7 etc

 

Keep a selection of lines is done already its ss.

 

You need to look into using IF's so you can ask a question like change color, even or odd.

 

(while (setq e (nth (setq i (+ i 2)) l))(ssadd e ss))
(setq ans (getstring "\nChange color Y or N "))
(if (or (= ans "Y")(= ans "y"))
(command "chprop" ss "" "color" "red" "")
)

 

Link to comment
Share on other sites

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