Select 4 differant line at once and get all the endpoints

Select 4 differant line at once and get all the endpoints

cadking2k5
Advocate Advocate
1,504 Views
10 Replies
Message 1 of 11

Select 4 differant line at once and get all the endpoints

cadking2k5
Advocate
Advocate

Here is what I have I want it to highlight the lines while I am selecting them but I need to get the endpoints of all of them for this command

(setq hor1 (entget (car (entsel "\nSelect the First horizontal line:"))))
  (setq hr1 (cdr(assoc 10 hor1)))
  (setq hr2 (cdr (assoc 11 hor1)))
  (setq hor2 (entget (car (entsel "\nSelect the second horizontal line:"))))
  (setq hr3 (cdr(assoc 10 hor2)))
  (setq hr4 (cdr(assoc 11 hor2)))
  (setq ang1 (entget (car (entsel "\nSelect the first Oblique line:"))))
  (setq an1 (cdr(assoc 10 ang1)))
  (setq an2 (cdr (assoc 11 ang1)))
  (setq ang2 (entget (car (entsel "\nSelect the second Oblique line:"))))
  (setq an3 (cdr(assoc 10 ang2)))
  (setq an4 (cdr (assoc 11 ang2)))

0 Likes
Accepted solutions (2)
1,505 Views
10 Replies
Replies (10)
Message 2 of 11

devitg
Advisor
Advisor

As ever , and as for the end of time. Please Upload a sample dwg .

Or how do you want the star and end points to be.?

 

0 Likes
Message 3 of 11

cadking2k5
Advocate
Advocate

just select it like you do any other command and and can it up getting the endpoints like this

(6.25 7.0 0.0)
(6.25 3.25 0.0)

0 Likes
Message 4 of 11

Ranjit_Singh
Advisor
Advisor
Accepted solution

Try below. You need to regen later to remove highlighting or call redraw with mode 4 on all the highlighted entities.

(progn
(setq hor1 (entget (setq hor11 (car (entsel "\nSelect the First horizontal line:"))))
      hr1  (cdr (assoc 10 hor1))
      hr2  (cdr (assoc 11 hor1)))
(redraw hor11 3)
(setq hor2 (entget (setq hor12 (car (entsel "\nSelect the second horizontal line:"))))
      hr3  (cdr (assoc 10 hor2))
      hr4  (cdr (assoc 11 hor2)))
(redraw hor12 3)
(setq ang1 (entget (setq ang11 (car (entsel "\nSelect the first Oblique line:"))))
      an1  (cdr (assoc 10 ang1))
      an2  (cdr (assoc 11 ang1)))
(redraw ang11 3)
(setq ang2 (entget (setq ang12 (car (entsel "\nSelect the second Oblique line:"))))
      an3  (cdr (assoc 10 ang2))
      an4  (cdr (assoc 11 ang2)))
(redraw ang12 3))

Maybe it is better to use ssget since it already provides the highlight effect. Once you have all the entities in the ss, process them as needed.

 

0 Likes
Message 5 of 11

cadking2k5
Advocate
Advocate

I can't use the SSGet in that you can't put in text I on this I have to put in text to tell them to select the Perpendicular lines then to select the Oblique lines

0 Likes
Message 6 of 11

cadking2k5
Advocate
Advocate

is there a way I can get the all four line 8 endpoints after I use the SSGET and I select all four lines at once 

0 Likes
Message 7 of 11

john.uhden
Mentor
Mentor
Accepted solution

If you want to pick them one at a time, then

 

(setq e (car (entsel "Your prompt: ")))
(vla-highlight (vlax-ename->vla-object e) 1)

Unless you erase, move, etc. each entity or perform a regen, you will have to unhighlight them when done...

 

(vla-highlight (vlax-ename->vla-object e) 0)

Might you want to select them instead, as in (command "_.select") or (ssget)?  That way they will be highlighted automatically (if HIGHLIGHT is ON) and all be in one selection set.

 

Just to be slightly critical, your code assumes that the user is actually picking a line, whereas he/she might pick some other object that doesn't possess both 10 and 11 DXF codes.

 

You could use a home-grown check for each entity picked...

 

(defun check (ent var1 var2)
  (if (= (cdr (assoc 0 ent)) "LINE")
    (progn
       (set var1 (cdr (assoc 10 ent)))
       (set var2 (cdr (assoc 11 ent)))
    )
    (progn
       (set var1 nil)
       (set var2 nil)
    )
  )
)

which you could use as...
(check ent 'p1 'p2)

Note that p1 and p2 are quoted and the check function uses set, not setq.  That way p1 and p2 are not local the the function but their values will be set inside the function and will exist outside the function.

John F. Uhden

0 Likes
Message 8 of 11

Ranjit_Singh
Advisor
Advisor

@cadking2k5 wrote:

is there a way I can get the all four line 8 endpoints after I use the SSGET and I select all four lines at once 


maybe like this

(mapcar '(lambda (x) (cdr (reverse (vl-remove-if-not 'listp (mapcar 'cdr (entget x))))))
        (vl-remove-if 'listp (mapcar 'cadr (ssnamex (ssget '((0 . "line")))))))
0 Likes
Message 9 of 11

devitg
Advisor
Advisor

Hi Cad King , yo did not accept  my previous post 

 

This one

 

As ever , and as for the end of time. Please Upload a sample dwg .

 

Neither 

 

Or how do you want the star and end points to be.?

 

 

0 Likes
Message 10 of 11

cadking2k5
Advocate
Advocate

Something like this

oblique.JPG

0 Likes
Message 11 of 11

john.uhden
Mentor
Mentor

If two of the lines are always horizontal then you can determine which ones in a selection set are horizontal by getting the angle from one end to the other.

 

That way you can filter your selection set for just lines...

   (princ "\nSelect all four (4) horizontal and diagonal lines...")

 

(setq ss (ssget '((0 . "LINE"))))

and then create two lists from the selection set...

(defun direction (ss / i e ent p1 p2 ang)
  (setq horizontals nil diagonals nil)
  (repeat (setq i (sslength ss))
    (setq e (ssname ss (setq i (1- i)))
          ent (entget e)
          p1 (cdr (assoc 10 ent))
          p2 (cdr (assoc 11 ent))
          ang (angle p1 p2)
    )
    (if (or (equal ang 0.0 0.01)(equal ang (* 2 pi) 0.01)(equal ang pi 0.01))
      (setq horizontals (cons e (horizontals))
      (setq diagonals (cons e diagonals))
    )
  )
)

(direction ss)

Note that the symbols 'horizontals' and 'diagonals' will be gobals (outside the direction function).

Also notice that I used equal with a small fuzz factor so that the horizontals don't have to be exactly horizontal.  Also, there's been plenty of discussion recently about comparing 'REAL numbers.  You can't use = and expect two reals to be exactly equal, even if they are to the eye.

 

A recent question in my Page-A-Day Trivia Facts calendar asked, "What did Mr. Spock do to disable an enemy space ship?"

"He instructed its on-board computer to compute all the decimal places of the number PI."

 

John F. Uhden

0 Likes