Comand select lines

Comand select lines

Anonymous
Not applicable
892 Views
5 Replies
Message 1 of 6

Comand select lines

Anonymous
Not applicable

Good afternoon. Is it possible to create a command that selects all lines, for example, with a 45° angle? Thank you.

0 Likes
893 Views
5 Replies
Replies (5)
Message 2 of 6

Kent1Cooper
Consultant
Consultant

QSELECT can do that:

 

Line45.PNG

 

But you would have to do it separately for the four  45-degree-angle directions [45, 135, 225, 315] if what you mean by 45 degrees is "generic" like that.

 

I believe they would also need to be precisely at the angle spelled out, which could sometimes miss ones you want it to find.  An AutoLisp routine could certainly be written that would be able to find all of them in all four of those directions that are within a specified tolerance  [fuzz factor] of precisely the right angles.

Kent Cooper, AIA
0 Likes
Message 3 of 6

Muhammed.OPERA
Advisor
Advisor

Hi @Kent1Cooper 

This question was asked in the AutoCAD Form and i answered that very answer but @Anonymous need the Code to do this Automatically. 


Muhammed Mamdouh (OPERA)
Structural Engineer, Instructor
Facebook |LinkedIn

EESignature

0 Likes
Message 4 of 6

Kent1Cooper
Consultant
Consultant

For Line entities only, try this [very lightly tested]:

 

(defun C:Lines45 (/ lines n line ldata ldelta)
  (setq lines45 (ssadd)); initially empty
  (if (setq lines (ssget "_X" '((0 . "LINE"))))
    (repeat (setq n (sslength lines))
      (setq
        line (ssname lines (setq n (1- n)))
        ldata (entget line)
        ldelta (mapcar '- (cdr (assoc 10 ldata)) (cdr (assoc 11 ldata)))
      ); setq
      (if
        (and
          (/= (car ldelta) 0); prevent division by zero [vertical]
          (equal (abs (atan (/ (abs (cadr ldelta)) (abs (car ldelta))))) (/ pi 4) 0.01)
; any 45-degree multiple direction within 0.01 radian [about 1/2 degree]
        ); and
        (ssadd line lines45)
      ); if
); repeat ); if (sssetfirst nil lines45); select/highlight/grip resulting set (princ) ); defun

 

No bells and whistles yet, but see what you think.  It leaves the selection in the non-localized 'lines45' variable, to do something with if a variable for that is intended.

Kent Cooper, AIA
Message 5 of 6

Anonymous
Not applicable

indeed, does not seem easy. the angle of 45° was just an example. specifically I need for the angles 0, 90, 180 and 270. and not for the entire drawing, but for the current selection. anyway thanks for this suggestion.

0 Likes
Message 6 of 6

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

.... I need for the angles 0, 90, 180 and 270. and not for the entire drawing, but for the current selection. anyway thanks for this suggestion.


Are you looking for something to find all Lines that run in any of those directions, together, or separate routines for each of those directions?  Either is achievable, with relatively minor adjustments to that code.

Kent Cooper, AIA
0 Likes