HARRY-PLOTTER Posted January 27, 2014 Share Posted January 27, 2014 How to find closest vertex to a selected point on a poly? Thanks! Quote Link to comment Share on other sites More sharing options...
MSasu Posted January 27, 2014 Share Posted January 27, 2014 Build a list of vertexes and distances from said point and sort it ascending; retain first element. Quote Link to comment Share on other sites More sharing options...
GP_ Posted January 27, 2014 Share Posted January 27, 2014 Build a list of vertexes and distances from said point and sort it ascending; retain first element. Another: (defun c:test () (setq a (vlax-ename->vla-object (car (entsel "\nSelect Polyline")))) (setq b (vlax-curve-getClosestPointTo a (trans (cadr (grread T)) 1 0))) (setq c (vlax-curve-getParamAtPoint a b)) (or (< (- c (setq c (fix c))) 0.50000000001) (setq c (1+ c))) (setq v (vlax-curve-getPointAtParam a c)) (princ (strcat "\nVertex n. " (itoa (1+ c)) " (" (rtos (car v)) " " (rtos (cadr v)) ")" )) (princ) ) Quote Link to comment Share on other sites More sharing options...
HARRY-PLOTTER Posted January 27, 2014 Author Share Posted January 27, 2014 thanks, perfect! Quote Link to comment Share on other sites More sharing options...
Tharwat Posted January 27, 2014 Share Posted January 27, 2014 There is no need to convert the object to with vlax-*** functions Quote Link to comment Share on other sites More sharing options...
Tharwat Posted January 27, 2014 Share Posted January 27, 2014 Another to add a green point at the nearest param . (defun c:Test (/ s e pr p pt a b) ;; Tharwat 2014. cadtutor ;; (if (and (setq s (entsel)) (eq (cdr (assoc 0 (entget (setq e (car s))))) "LWPOLYLINE")) (progn (setq pr (vlax-curve-getparamatpoint (car s) (setq p (vlax-curve-getclosestpointto (car s) (cadr s))))) (if (< (distance p (setq a (vlax-curve-getpointatparam (car s) (fix pr)))) (distance p (setq b (vlax-curve-getpointatparam (car s) (1+ (fix pr))))) ) (setq pt a) (setq pt b) ) (entmakex (list '(0 . "POINT") (cons 10 pt) '(62 . 3))) ) (princ "\n Nothing selected or not a Polyline <!>") ) (princ) ) (vl-load-com) Quote Link to comment Share on other sites More sharing options...
GP_ Posted January 27, 2014 Share Posted January 27, 2014 thanks, perfect! You're welcome There is no need to convert the object to with vlax-*** functions Oops Quote Link to comment Share on other sites More sharing options...
MSasu Posted January 28, 2014 Share Posted January 28, 2014 There is no need to convert the object to with vlax-*** functions The type of the argument for VLAX-CURVE-* functions family is listed in help as The VLA-object to be measuredso a good programming practice will be to comply, even if entity name is supported. This will ensure a running code if one day Autodesk decide to enforce the rule (it has happened in the past, although I don't recall the function in case). Quote Link to comment Share on other sites More sharing options...
Tharwat Posted January 28, 2014 Share Posted January 28, 2014 I don't think that Autodesk cares about any developments towards Autolisp anymore , since they're forcing their horses to VB.net for a long time now . Quote Link to comment Share on other sites More sharing options...
Kowal Posted January 30, 2014 Share Posted January 30, 2014 How to get the closest and the opposite point on the segment of the polyline? Quote Link to comment Share on other sites More sharing options...
marko_ribar Posted January 30, 2014 Share Posted January 30, 2014 (defun c:Test ( / s e pr p pt a b ) (vl-load-com) ;; Tharwat 2014. cadtutor - mods by M.R. ;; (if (and (setq s (entsel)) (wcmatch (cdr (assoc 0 (entget (setq e (car s))))) "*POLYLINE")) (progn (setq pr (vlax-curve-getparamatpoint (car s) (setq p (vlax-curve-getclosestpointto (car s) (cadr s))))) (setq a (vlax-curve-getpointatparam (car s) (fix pr))) (setq b (vlax-curve-getpointatparam (car s) (1+ (fix pr)))) (entmakex (list '(0 . "POINT") (cons 10 a) '(62 . 3))) (entmakex (list '(0 . "POINT") (cons 10 b) '(62 . 3))) ) (princ "\n Nothing selected or not a Polyline <!>") ) (princ) ) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.