Routine that selects lines of the same length

Routine that selects lines of the same length

isaacV7RNV
Explorer Explorer
718 Views
5 Replies
Message 1 of 6

Routine that selects lines of the same length

isaacV7RNV
Explorer
Explorer

I know qsel does this but is there a faster version?
I dont want to have to copy the line length and go into qsel everytime.

Anyone have a routine like this or similar i can edit?

0 Likes
Accepted solutions (1)
719 Views
5 Replies
Replies (5)
Message 2 of 6

paullimapa
Mentor
Mentor

how's about this code on this old thread:

filtering lines by length - Autodesk Community - Community Archive - Read Only


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 3 of 6

isaacV7RNV
Explorer
Explorer

Ive seen that one but its also a bit tedious. These lines have multiple decimal places so itd be handy to just select the line I want and it selects the rest of them that are the same. 
I might try and work on this code then if theres no other solutions 

0 Likes
Message 4 of 6

paullimapa
Mentor
Mentor

should be pretty straight forward to do a selection of a line object and then use the part of the code that's already given to the get the length of the line selected:

 

(while (not ent)
 (setq ent (ssget "_+.:E:S" '(( 0 . "LINE")))) ; select line
)
; get length of selected line
(setq ent (ssname ent 0)
      STPT (cdr (assoc 10 (entget ENT))) ; start point of selected line
      ENPT (cdr (assoc 11 (entget ENT))) ; end point of selected line
      LEN (distance STPT ENPT) ; length of selected line
) ;end setq

 

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 5 of 6

hak_vz
Advisor
Advisor
(defun c:sbl ( /  eo do ss  ssl i)	 
	(setq ss nil)
	(princ "\nSelect line to collect required length!")
	(while (null ss)(setq ss (ssget "+.:E:S" '(( 0 . "LINE")))))
	(setq 
		eo (vlax-ename->vla-object (ssname ss 0))
		d (vlax-get eo 'length)
	)
	(setq ss (ssget "X" '((0 . "LINE"))) ssl (ssadd) i -1)
	(while (< (setq i (1+ i))(sslength ss))
		(setq 
			eo (vlax-ename->vla-object (ssname ss i))
			do (vlax-get eo 'length)
		)
		(if (<= (abs(- do d)) 1e-10)(setq ssl (ssadd (ssname ss i) ssl)))
	)	
	 (sssetfirst nil ssl)

	 (princ)
)

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 6 of 6

Kent1Cooper
Consultant
Consultant
Accepted solution

Another similar way [similar in finding all Lines and comparing the length of each to that of the reference Line, and leaving you with the qualifying ones selected/gripped/highlighted], but that involves no extraction of Line endpoints or VLA object conversion to get the reference or comparison lengths, nor multiple selection sets:

(defun C:SLSL  (/ lsel reflen n lin ss); = Select Lines of Same Length	 
  (if
    (and
      (setq lsel (entsel "\nSelect Line of reference length: "))
      (member '(0 . "LINE") (entget (car lsel)))
    ); and
    (progn ; then
      (setq reflen (getpropertyvalue (car lsel) "Length"))
      (repeat (setq n (sslength (setq ss (ssget "X" '((0 . "LINE")))))); then
        (setq lin (ssname ss (setq n (1- n))))
        (if (not (equal (getpropertyvalue lin "Length") reflen 1e-2))
          (ssdel lin ss); remove
        ); if
      ); repeat
      (sssetfirst nil ss)
    ); progn
    (prompt "\nNo LINE selected."); else
  ); if
  (prin1)
)

[Yes, I know selection can be limited to a single Line in (ssget), but you can't escape its "Select objects: " prompt always in the plural, so I don't like to use it when going for a single thing.  I go for (entsel) in which you can specify your own prompt within the selection function itself.]

That defines "same length" as being within 1/100 of a drawing unit.  Adjust the 1e-2 for a different precision, or the routine could be made to ask for a precision, and if you like, remember it for subsequent use.

Kent Cooper, AIA
0 Likes