Draw line from one endpoint of lines selected in window

Draw line from one endpoint of lines selected in window

jamieq
Collaborator Collaborator
1,432 Views
7 Replies
Message 1 of 8

Draw line from one endpoint of lines selected in window

jamieq
Collaborator
Collaborator

I want to draw a line from one endpoint of each lines selected in a window. I want the endpoint drawn from to be the endpoint within the selection window. I prefer if the lines are drawn from selected lines only if those selected lines have only one endpoint within the selection window. However, I am ok with it drawing from both endpoints if they are both contained within the selection window. I've attached a few crude sketches. the before sketch shows the original lines with the selection window. The after shows the lines drawn from the selected endpoints. The after alt shows the lines drawn if both endpoints are selected within the selection window. I'm not particularly concerned about the angle, length, etc of the line drawn. Just making sure it gets drawn from the selected endpoints. Thanks!before.pngafter.pngafter alt.png

0 Likes
Accepted solutions (1)
1,433 Views
7 Replies
Replies (7)
Message 2 of 8

Kent1Cooper
Consultant
Consultant
Accepted solution

Try this.  I took the liberty of assuming that if you don't care how long or in what direction the added little Lines are, then what you really want to do is simply identify those inside-the-window ends, and I chose to do that more simply with Points instead of Lines, setting the PDMODE and PDSIZE System Variables to ensure their visibility.  No error handling or other typical features yet, and lightly tested:

 

(defun C:LEIW ; = Line End In Window
  (/ inside cor1 cor2 LL UR lineData lineStart lineEnd)
  (defun inside (pt)
    (and
      (<= (car LL) (car pt) (car UR))
      (<= (cadr LL) (cadr pt) (cadr UR))
    ); and
  ); defun -- inside
  (setvar 'pdmode 35); <-- EDIT as desired
  (setvar 'pdsize 0); <-- EDIT as desired
  (setq
    cor1 (getpoint "\nCorner of selection window: ")
    cor2 (getcorner cor1 "\nOpposite corner: ")
    LL (mapcar 'min cor1 cor2)
    UR (mapcar 'max cor1 cor2)
  ); setq
  (if (setq liness (ssget "_C" cor1 cor2 '((0 . "LINE"))))
    (repeat (setq n (sslength liness))
      (setq
        lineData (entget (ssname liness (setq n (1- n))))
        lineStart (cdr (assoc 10 lineData))
        lineEnd (cdr (assoc 11 lineData))
      ); setq
      (cond
        ((and (inside lineStart) (not (inside lineEnd)))
          (command "_.point" "_none" lineStart)
        ); start only
        ((and (not (inside lineStart)) (inside lineEnd))
          (command "_.point" "_none" lineEnd)
        ); end only
      ); cond
    ); repeat
  ); if
  (princ)
); defun -- C:LEIW

 

It could be made to draw Lines instead, without much difficulty, but something would need to be decided about length -- an absolute length could be invisibly small or grossly over-long, depending on the lengths of selected Lines, so something relative  would be better, but should it be a percentage of each  Line's length, or of the screen height, or...?

 

Also, a Line endpoint that sits exactly on  an edge of the selection window would be considered "inside"  it by the above.  If you don't want that, take the = signs out of the (<=) functions in the (inside) function definition.

Kent Cooper, AIA
0 Likes
Message 3 of 8

Ranjit_Singh
Advisor
Advisor

Here is another option. Minimal testing.

;;Ranjit Singh
;;6/22/17
(defun c:somefunc  (/ cp ll pt pts ur)
 (setq cp (last (ssnamex (ssget "_c" (setq pt (getpoint "\nPick corner point: ")) (getcorner pt "\nPick next corner point: ")))))
 (setq ll (cadr (last cp))
       ur (car (cdaddr cp)))
 (mapcar
  '(lambda (x)
    (setq pt (car
              (vl-remove-if-not '(lambda (x) (apply 'and (mapcar '< ll (reverse (cdr (reverse x))) ur)))
                                (setq pts (cdr (reverse (vl-remove-if-not 'listp (mapcar 'cdr (entget x)))))))))
    (entmakex (list '(0 . "line")
                    (cons 10 pt)
                    (cons 11 (polar pt (+ (* 0.5 pi) (angle pt (car (vl-remove pt pts)))) 0.1))))); 0.1 units length of leg
(mapcar 'cadr (ssnamex 
(ssget "_x" (list '(0 . "line") '(-4 . "<or") '(-4 . "<xor") 
'(-4 . "<and") '(-4 . ">,>") (list 10 (car ll) (cadr ll) 0) '(-4 . "<,<") (list 10 (car ur) (cadr ur) 0) '(-4 . "and>")
'(-4 . "<and") '(-4 . ">,>") (list 11 (car ll) (cadr ll) 0) '(-4 . "<,<") (list 11 (car ur) (cadr ur) 0) '(-4 . "and>") '(-4 . "xor>")
'(-4 . "<xor") '(-4 . "<and") '(-4 . "<,<") (list 10 (car ur) (cadr ur) 0) '(-4 . ">,>") (list 10 (car ll) (cadr ll) 0) '(-4 . "and>")
'(-4 . "<and") '(-4 . "<,<") (list 11 (car ur) (cadr ur) 0) '(-4 . ">,>") (list 11 (car ll) (cadr ll) 0) '(-4 . "and>") '(-4 . "xor>") '(-4 . "or>")))))))

 

Z_Legs.gif

 

0 Likes
Message 4 of 8

jamieq
Collaborator
Collaborator

This is perfect! I adjusted it a bit to fit my needs, but it was exactly what I needed. I had thought along the lines of your idea of checking if the endpoint was in the crossing, but couldn't quite figure it out, and looking at your way of doing it, I probably wouldn't have. Thanks so much! I've already written the rest of my code for what I wanted drawn at the ends of the lines, and I'm in business. 

0 Likes
Message 5 of 8

stevor
Collaborator
Collaborator

Probably Kents code could be changed into making LINEs easily,

if you already used it, and is shorter than mine,

which is broader to do other things.

 

Mine presumes a 90d CCW, turn angle, and 10 % line length,

which can be changed of course: it is Autolisp.

S
0 Likes
Message 6 of 8

abdulellah.alattab
Advocate
Advocate

very helpfully and professionally  < can add option ask about angle other than 90 degree ? plz 

0 Likes
Message 7 of 8

jamieq
Collaborator
Collaborator

It's very easy to add an option for an angle other than 90 degrees. But what else do you want to do? Ken's original reply is what I used to check for endpoints within a selection window, and from there I wrote the rest of my code (which was way more than drawing lines at 90 degrees). But I can help you get what you need done.