Jump to content

Select an Endpoint


Small Fish

Recommended Posts

If I wanted to check if the user has selected a point I

would have some code as set out below;

 

 
(setq Pt1 (getpoint "\n pick point"))
   (if Pt1  
         (progn
                    ;do some stuff 
          )        
        (alert "Nothing Picked.")  
       )

 

However how can I check if the user has selected an "endpoint" of a line or pline?

thanks

Link to comment
Share on other sites

one way is :

(if (and (setq Pt1 (getpoint "\n pick point"))
        (setq Pt1 (osnap Pt1 "_ENDP"))
   )
 (alert (vl-princ-to-string Pt1))
 ;; else
 (alert "Ooops")
)

 

[added]

This does not actually check that the selected Point IS an endpoint ( you'll need to write explicit code for that) .. it forces the point value to the nearest ENDPOINT of the entity under the selection PickBox when the initial point is selected.

Edited by Kerry Brown
Link to comment
Share on other sites

Pretty easy you pick the line entsel you then compare the distance between pick pt and end & start pts the shorter distance is the end you want.

 

here is the answer

 

(setq tp1 (entsel "\nSelect left side inner wall near end : "))
(setq tpp1 (entget (car tp1)))
(setq pt1 (cdr (assoc 10 tpp1)))      
(setq pt2 (cdr (assoc 11 tpp1)))      
(setq pt3 (cadr tp1))
 (setq d1 (distance pt1 pt3))
(setq d2 (distance pt2 pt3))
 (if (> d1 d2)
 (progn 
  (setq temp pt1)
  (setq pt1 pt2)
  (setq pt2 temp)
 )
 )

 

nice thing is you can pull other stuff out as well layer colour etc

Link to comment
Share on other sites

Here is another code that would get the end point of a line, almost as BIGAL 's codes action ...

 

(vl-load-com)
(if (setq Lin (ssget "_+.:S" '((0 . "LINE"))))
 (progn
   (setq Ent (ssname Lin 0)
  Obj (vlax-ename->vla-object Ent)
  End (vlax-get obj 'endpoint)
  )
   )
 (alert "Nothing's Picked")
 )

 

Tharwat

Edited by Tharwat
Alert function added
Link to comment
Share on other sites

My version

(Defun Get_End_Point (/ oldosmod flag point)
 (vl-load-com)
 (setq	oldosmod (getvar 'OSMODE)
flag	 T
 )
 (vl-catch-all-apply
   (function
     (lambda ()
(setvar 'OSMODE 1)
(while flag
  (setq	point (getpoint "\nSelect an Endpoint <Exit>:")
  )
  (cond
    ((not point)
     (setq flag	nil
	   point nil
     )
    )
    ((ssget point) (setq flag nil))
    (t (princ "\n Miss"))
  )
)
     )
   )
 )
 (setvar 'OSMODE oldosmod)
 point
)

Link to comment
Share on other sites

Here is another code that would get the end point of a line, almost as BIGAL 's codes action ...

 

(vl-load-com)
(if (setq Lin (ssget "_+.:S" '((0 . "LINE"))))
(progn
(setq Ent (ssname Lin 0)
Obj (vlax-ename->vla-object Ent)
End (vlax-get obj 'endpoint)
)
)
(alert "Nothing's Picked")
)

 

Tharwat

 

A couple of things:

1) The PROGN is redundant (not necessary) in your sample.

2) You have ASSUMED the user will select the 'endpoint of the line ... in your code the 'endpoint is returned irrespective of the end actually selected.

Did you test the code ??

Link to comment
Share on other sites

A couple of things:

1) The PROGN is redundant (not necessary) in your sample.

2) You have ASSUMED the user will select the 'endpoint of the line ... in your code the 'endpoint is returned irrespective of the end actually selected.

Did you test the code ??

 

Hello Kerry.

 

You are right about (progn) function, actually the rest of codes after that function were like (setq ..... and ( setq ..... so on . I have

forgotten to remove it.

 

I did test the codes very well , and as you know it would give the coordinates of the end point of the selected line. which is not to check if the

user has selected a point as as the questioner asked for.

 

I agree with you.

 

Thanks for your attention.

 

Tharwat

Link to comment
Share on other sites

It appeared to me that the OP was trying to select a curve and snap to the closest endpoint. A curve has one Start and End point, however it will have at least two points to which an EndPoint snap can pick.

 

How about this?

(defun foo (/ e)
 (if (setq e (entsel))
   (osnap (cadr e) "_ENDP")
 )
)

Link to comment
Share on other sites

For fun...

 

(defun AT:ClosestPoint (ep / _next _dist ep el lst)
 ;; Return closest point to selected entity
 ;; ep - entity and point list
 ;; Alan J. Thompson, 09.14.10
 (defun _next (e / p)
   (if (and (setq e (entnext e)) (setq p (cdr (assoc 10 (entget e)))))
     (cons p (_next e))
   )
 )
 (defun _dist (a b) (distance (list (car a) (cadr a)) (list (car b) (cadr b))))
 (if
   (and (vl-consp ep)
        (eq (type (car ep)) 'ENAME)
        (or (eq 1 (getvar 'worlducs)) (setq ep (list (car ep) (trans (cadr ep) 1 0))))
        (cond
          ((vl-position (cdr (assoc 0 (setq el (entget (car ep))))) '("ARC" "LINE" "SPLINE"))
           (setq lst (list (vlax-curve-getStartPoint (car ep)) (vlax-curve-getEndPoint (car ep))))
          )
          ((eq (cdr (assoc 0 el)) "LWPOLYLINE")
           (foreach p el (and (eq (car p) 10) (setq lst (cons (cdr p) lst))))
           lst
          )
          ((eq (cdr (assoc 0 el)) "POLYLINE") (setq lst (_next (car ep))))
        )
   )
    (car (vl-sort lst (function (lambda (a b) (< (_dist a (cadr ep)) (_dist b (cadr ep)))))))
 )
)

eg.

(defun c:Test (/ p)
 (if (setq p (AT:ClosestPoint (entsel "\nSelect curve: ")))
   (entmake (list '(0 . "CIRCLE") (cons 10 p) '(40 . 10.)))
 )
 (princ)
)

Edited by alanjt
Link to comment
Share on other sites

Wow how many ways to find an endpoint !

 

Just a quick explanation of my code was used for housing to actually nominate how far from an end to start something else door window and knowing what part of the wall you are in, just getting end could draw a door in the wrong wall, bearing in mind a wall is made up of multiple elements also, the code is about 10 years old prior to vla and autocad architect.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...