RepCad Posted December 8, 2020 Posted December 8, 2020 (edited) Hello everyone, My drawing has lots of rectangle with a polyline connected to it that polyline has two points and I need to get the farthest point on the polyline from rectangle after selecting rectangle. as I've shown the pink point is I mean. it means I want to select all rectangles and then function specify the point on each green polyline. Thanks in advance. Test.coordinate.dwg Edited December 8, 2020 by amir0914 Quote
BIGAL Posted December 11, 2020 Posted December 11, 2020 If I understand correct (defun c:test ( / obj1 obj2 co-ord end start) (While (setq obj1 (entsel "\nPick rectangle Enter to exit ")) (setq obj2 (vlax-ename->vla-object (car (entsel "\nPick other line ")))) (setq co-ord (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget (car obj1))))) (setq end (vlax-curve-getendpoint obj2)) (setq start (vlax-curve-getstartpoint obj2)) (if (> (distance (nth 0 co-ord) start) (distance (nth 0 co-ord) end)) (command "point" start) (command "point" end) ) (setvar 'pdmode 35) ) (princ) ) 1 Quote
RepCad Posted December 11, 2020 Author Posted December 11, 2020 Thank you, that's exactly what I want. Quote
RepCad Posted December 11, 2020 Author Posted December 11, 2020 (edited) 11 hours ago, BIGAL said: If I understand correct (defun c:test ( / obj1 obj2 co-ord end start) (While (setq obj1 (entsel "\nPick rectangle Enter to exit ")) (setq obj2 (vlax-ename->vla-object (car (entsel "\nPick other line ")))) (setq co-ord (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget (car obj1))))) (setq end (vlax-curve-getendpoint obj2)) (setq start (vlax-curve-getstartpoint obj2)) (if (> (distance (nth 0 co-ord) start) (distance (nth 0 co-ord) end)) (command "point" start) (command "point" end) ) (setvar 'pdmode 35) ) (princ) ) Is it possible to select the line ("obj2") automatically by the program? (Without entsel or select manually) Edited December 11, 2020 by amir0914 Quote
Jonathan Handojo Posted December 12, 2020 Posted December 12, 2020 ;; ss - the selection set of rectangles ;; lns - the selection set of lines ;; tol - intersection tolerance (defun furthestpt (ss lns tol / ent ep i rtn ssl sp) (repeat (setq i (sslength ss)) (setq i (1- i) ssl (cons (ssname ss i) ssl)) ) (repeat (setq i (sslength lns)) (setq i (1- i) ent (ssname lns i) sp (vlax-curve-getStartPoint ent) ep (vlax-curve-getEndPoint ent) rtn (cons (vl-some '(lambda (x) (cond ((equal sp (vlax-curve-getClosestPointTo x sp) tol) ep) ((equal ep (vlax-curve-getClosestPointTo x sp) tol) sp) ) ) ssl ) rtn ) ) ) (reverse rtn) ) (defun c:test nil (furthestpt (ssget "_X" '((0 . "LWPOLYLINE") (62 . 1) (410 . "Model"))) (ssget "_X" '((0 . "LWPOLYLINE") (62 . 3) (410 . "Model"))) 1e-6 ) ) 1 Quote
BIGAL Posted December 12, 2020 Posted December 12, 2020 It is possible can offset the rectangs and check what do they touch which if dwg is 100% correct would be the green *lines. (defun c:test ( / ) (setq olsnap (getvar 'Osmode)) (While (setq obj1 (entsel"\nPick rectangle Enter to exit ")) (setvar 'osmode 0) (setq co-ord (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget (car obj1))))) (setq pt (getvar 'extmax)) (setq pt (list (car pt)(cadr pt))) (command "offset" 200 obj1 pt "") (setq co-ord2 (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget (entlast))))) (setq co-ord2 (cons (last co-ord2) co-ord2)) (command "erase" (entlast) "") (setq obj2 (vlax-ename->vla-object (ssname (ssget "F" co-ord2 (list (cons 0 "*LINE"))) 0))) (setq end (vlax-curve-getendpoint obj2)) (setq start (vlax-curve-getstartpoint obj2)) (if (> (distance (nth 0 co-ord) start) (distance (nth 0 co-ord) end)) (command "point" start) (command "point" end) ) (setvar 'pdmode 35) ) (setvar 'osmode oldsnap) (princ) ) 1 Quote
RepCad Posted December 13, 2020 Author Posted December 13, 2020 My problem has been resolved, thank you both. 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.