EnM4st3r Posted February 4, 2025 Posted February 4, 2025 Hi, im trying to get the closest endpoint of a 3D Line from a single Selection. I tried to retrieve the location using ssnamex, wich is working in 2d, but not in 3d from a 3d view. the Z location somehow always gets messed up in the selection so its not reliable. Any Ideas? Here is the code im using (defun c:foo (/ ss selPt obj startPt endPt pt1) (while (not ss) (setq ss (ssget "_+.:E:S" '((0 . "LINE")))) ) (setq selPt (cadr (nth 3 (car (ssnamex ss 0))))) ; get point of selection (setq obj (vlax-ename->vla-object (ssname ss 0))) (setq startPt (vlax-curve-getStartPoint obj)) (setq endPt (vlax-curve-getEndPoint obj)) ;; Determine closer endpoint (if (< (distance selPt startPt) (distance selPt endPt)) (setq pt1 startPt) (setq pt1 endPt) ) (vla-put-color (vla-addcircle (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))) (vlax-3d-point pt1) 10) acRed) ;circle for testing ) Quote
GLAVCVS Posted February 4, 2025 Posted February 4, 2025 Hello It is better if you attach an example drawing Quote
Lee Mac Posted February 4, 2025 Posted February 4, 2025 I would suggest using the point returned by entsel corresponding to the center of the pickbox aperture, expressed in UCS, e.g.: (defun c:foo ( / cpt enx ocs pt1 pt2 sel ) (if (and (setq sel (entsel)) (= "LINE" (cdr (assoc 0 (setq enx (entget (car sel)))))) ) (progn (setq ocs (trans '(0 0 1) 1 0 t) cpt (trans (cadr sel) 1 0) pt1 (cdr (assoc 10 enx)) pt2 (cdr (assoc 11 enx)) ) (if (< (distance pt2 cpt) (distance pt1 cpt)) (setq pt1 pt2) ) (entmake (list '(000 . "CIRCLE") '(040 . 1) '(062 . 1) (cons 010 (trans pt1 0 ocs)) (cons 210 ocs) ) ) ) ) (princ) ) Quote
EnM4st3r Posted February 4, 2025 Author Posted February 4, 2025 test.dwg Here is a example. From this point of view i cant seem to get the upper endpoint of the green line. Quote
EnM4st3r Posted February 4, 2025 Author Posted February 4, 2025 (edited) 39 minutes ago, Lee Mac said: I would suggest using the point returned by entsel corresponding to the center of the pickbox aperture, expressed in UCS, e.g.: I also tried entsel, but the problem remained esentially the same. Entsel seems to ignore the Z value and always sets it to 0.0 Also what is the ocs for in your code? Edited February 4, 2025 by EnM4st3r Quote
LanloyLisp Posted February 4, 2025 Posted February 4, 2025 (defun c:foo (/ ss selPt obj startPt endPt pt1) (while (not ss) (setq ss (ssget "_+.:E:S" '((0 . "LINE")))) ) (setq selPt (trans (cadr (nth 3 (car (ssnamex ss 0)))) 0 2)) ; get point of selection (setq obj (vlax-ename->vla-object (ssname ss 0))) (setq startPt (reverse (cdr (reverse (trans (vlax-curve-getStartPoint obj) 0 2))))) (setq endPt (reverse (cdr (reverse (trans (vlax-curve-getEndPoint obj) 0 2))))) ;; Determine closer endpoint (if (< (distance selPt startPt) (distance selPt endPt)) (setq pt1 startPt) (setq pt1 endPt) ) (vla-put-color (vla-addcircle (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))) (vlax-3d-point (trans pt1 2 0)) 10) acRed) ;circle for testing ) Hi EnM4st3r, Try the edited code above if it works for you. 2 Quote
EnM4st3r Posted February 4, 2025 Author Posted February 4, 2025 9 minutes ago, LanloyLisp said: Hi EnM4st3r, Try the edited code above if it works for you. Nice. It only placed them visually tough, not on the exact endpoints. I changed it a little, seems to work now. (defun c:foo (/ ss selPt obj pt1 pt2) (while (not ss) (setq ss (ssget "_+.:E:S" '((0 . "LINE")))) ) (setq selPt (trans (cadr (nth 3 (car (ssnamex ss 0)))) 0 2)) ; get point of selection (setq obj (vlax-ename->vla-object (ssname ss 0))) (setq pt1 (vlax-curve-getStartPoint obj)) (setq pt2 (vlax-curve-getEndPoint obj)) ;; Determine closer endpoint (if (< (distance selPt (reverse (cdr (reverse (trans pt2 0 2))))) (distance selPt (reverse (cdr (reverse (trans pt1 0 2))))) ) (setq pt1 pt2) ) (vla-put-color (vla-addcircle (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))) (vlax-3d-point pt1) 10) acRed) ;circle for testing ) 1 Quote
Lee Mac Posted February 4, 2025 Posted February 4, 2025 43 minutes ago, EnM4st3r said: Also what is the ocs for in your code? Circles are planar entities and defined relative to the OCS. 1 Quote
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.