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

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

pankaj
Contributor Contributor
435 Views
3 Replies
Message 1 of 4

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

pankaj
Contributor
Contributor

Hello guys,

I need LISP for Selection of alternate lines from the selection set of lines(horizontal, vertical & Angular) like 1st, 3rd, 5th, .....etc lines in Autocad.

I am attaching the file with my requirement in the following cases,
Case 1: Angular lines
Case 2: vertical lines(angle 90 or 270 degree angle lines)
Case 3
: Horizontal lines(angle 0 & 180 degree angle lines)


For Case 2 & Case 3 i got the solution of lisp from the following link
https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-to-select-a-set-object-in-alter...
with the following code by komondormrex(Thanks you sir)

;*****************************************************************************************************************************************************

(defun c:even_odd_alternate_pattern_sset ( / lines_sset lines_sset_list command_terminated odd_order line_angle testing_coordinate
											 alternate_sset alternate_index ename
										 )
	(if (setq lines_sset (cadr (ssgetfirst)))
		(sssetfirst)
		(setq lines_sset (ssget '((0 . "line"))))
	)
 	(setq lines_sset_list (vl-remove-if 'listp (mapcar 'cadr (ssnamex lines_sset))))
	(cond
		(
			(or
				(equal (* 1.5 pi) (setq line_angle (vla-get-angle (vlax-ename->vla-object (car lines_sset_list)))) 1e-2)
				(equal (* 0.5 pi) line_angle 1e-2)
			)
				(setq testing_coordinate 'car)		;	vertical
		)
		(
			(or
				(equal (* 0.0 pi) line_angle 1e-2)
				(equal (* 1.0 pi) line_angle 1e-2)
			)
				(setq testing_coordinate 'cadr) 	;	horizontal
		)
		(
			t
				(setq testing_coordinate 'skip)
		)
	)
	(if (not (= testing_coordinate 'skip))
		(setq lines_sset_list (vl-sort (mapcar '(lambda (line) (cons line (apply testing_coordinate (list (vlax-get (vlax-ename->vla-object line) 'startpoint)))))
												lines_sset_list
									   )
									   '(lambda (line_1 line_2) (< (cdr line_1) (cdr line_2)))
							  )
		)
	)
	(sssetfirst nil lines_sset)
	(prompt "\rPress <Space> to see alternate pattern, <Esc,Enter> to confirm")
	(while (not command_terminated)
			(setq error_occurred (if (vl-catch-all-error-p (setq grread_data (vl-catch-all-apply 'grread (list t 12 0)))) t nil))
	    	(cond
				(
					error_occurred                                                              ;	Esc
						(setq command_terminated t)
				)
				(
				 	(equal grread_data '(2 32))													;	Space
						(prompt "\rPress <Space> to see alternate pattern, <Esc,Enter> to confirm")
						(sssetfirst)
						(setq alternate_sset (ssadd)
							  alternate_index 0
						)
						(if odd_order
							(setq alternate_index 1)
							(setq alternate_index 0)
						)
					  	(setq odd_order (not odd_order))
						(while (setq ename (car (nth alternate_index lines_sset_list)))
							(ssadd ename alternate_sset)
							(setq alternate_index (+ 2 alternate_index))
						)
						(sssetfirst nil alternate_sset)
				)
				(
				 	(equal grread_data '(2 13))													;	Enter
						(setq command_terminated t)
				)
			)
	)
	(princ)
)

 

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

Thanks in advance,
Pankaj

0 Likes
Accepted solutions (3)
436 Views
3 Replies
Replies (3)
Message 2 of 4

Sea-Haven
Mentor
Mentor
Accepted solution
0 Likes
Message 3 of 4

komondormrex
Mentor
Mentor
Accepted solution

hey,

check the following. alternating ssets are formed from originally fenced entities.

 

 

;*************************************************************************************************************************************************

(defun crd (_list)
	(reverse (cdr (reverse _list)))
)

;*************************************************************************************************************************************************

(defun draw_pline (point_list pline_exist / pline_coordinates_array pline_coordinates_List)
    (setq pline_coordinates_array (vlax-make-safearray
										vlax-vbdouble
								  	    (cons 1 (length (setq pline_coordinates_list
													   		(apply 'append
																   (mapcar 'crd
																			(mapcar '(lambda (point) (trans point 1 0))
																					 point_list
																			)
																   )
															)
													   )
												)
										)
								  )
	)
    (vlax-safearray-fill pline_coordinates_array pline_coordinates_list)
	(if pline_exist
    	(vla-put-coordinates fence_object pline_coordinates_array)
		(progn
			(setq fence_object (vla-addlightweightpolyline (vla-get-block (vla-get-activelayout (vla-get-activedocument (vlax-get-acad-object))))
														   pline_coordinates_array
							   )
			)
			(vla-put-color fence_object 1)
			(vla-put-constantwidth fence_object 30)
		)
	)
)

;*************************************************************************************************************************************************

(defun c:even_odd_alternate_pattern_sset (/ fence_list fence_object pline_exist next_point lines_sset_list command_terminated 
											error_occurred grread_data alternate_sset alternate_index odd_order ename
										 )
	(setq fence_list (append fence_list (list (setq next_point (getpoint "\nPick starting point for object selecting with fence: ")))))
	(while (setq next_point (getpoint next_point "\nPick next point for object selecting with fence (RMB to stop fencing): "))
		(setq fence_list (append fence_list (list next_point)))
		(draw_pline fence_list pline_exist)
		(if (not pline_exist) (setq pline_exist t))
		(sssetfirst nil (setq lines_sset (ssget "_f" fence_list)))
	)
	(vla-erase fence_object)
	(setq lines_sset_list (vl-remove-if 'listp (mapcar 'cadr (ssnamex lines_sset))))
	(prompt "\rPress <Space> to see alternate pattern, <Esc or Enter> to confirm")
	(while (not command_terminated)
			(setq error_occurred (if (vl-catch-all-error-p (setq grread_data (vl-catch-all-apply 'grread (list t 12 0)))) t nil))
	    	(cond
				(
					error_occurred                                                              		;	Esc
						(setq command_terminated t)
				)
				(
				 	(equal grread_data '(2 32))															;	Space
						(prompt "\rPress <Space> to see alternate pattern, <Esc or Enter> to confirm")
						(sssetfirst)
						(setq alternate_sset (ssadd)
							  alternate_index 0
						)
						(if odd_order
							(setq alternate_index 1)
							(setq alternate_index 0)
						)
					  	(setq odd_order (not odd_order))
						(while (setq ename (nth alternate_index lines_sset_list))
							(ssadd ename alternate_sset)
							(setq alternate_index (+ 2 alternate_index))
						)
						(sssetfirst nil alternate_sset)
				)
				(
				 	(equal grread_data '(2 13))															;	Enter
						(setq command_terminated t)
				)
			)
	)
	(princ)
)

;*************************************************************************************************************************************************

 

0 Likes
Message 4 of 4

Kent1Cooper
Consultant
Consultant
Accepted solution

@pankaj wrote:

...
I need LISP for Selection of alternate lines from the selection set of lines(horizontal, vertical & Angular) like 1st, 3rd, 5th, .....etc lines in Autocad.
...,
Case 1: Angular lines
Case 2: vertical lines(angle 90 or 270 degree angle lines)
Case 3
: Horizontal lines(angle 0 & 180 degree angle lines)


For Case 2 & Case 3 i got the solution ....

Please help me out with an possible lisp solution for case 1.
....


>This< from that other topic works on angular lines.

Kent Cooper, AIA
0 Likes