Jump to content

Get farthest point


RepCad

Recommended Posts

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.

 

Screenshot (1931).png

Test.coordinate.dwg

Edited by amir0914
Link to comment
Share on other sites

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)
)

 

  • Like 1
Link to comment
Share on other sites

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 by amir0914
Link to comment
Share on other sites

;; 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
	)
    )

 

  • Like 1
Link to comment
Share on other sites

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)
)

 

  • Like 1
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...