Akanezuko Posted September 18 Posted September 18 I need a lisp file where I can get corner points of a polygon instead of whole vertices. Quote
Isaac26a Posted September 18 Posted September 18 Could you explain what you mean for corner points, is ti like bounding box?, Maybe a graphic illustration would help. 1 Quote
Lee Mac Posted September 18 Posted September 18 Assuming rectangular bounding box for LWPolyline - (defun polybb ( ent ) ( (lambda ( lst ) (mapcar '(lambda ( x ) (apply 'mapcar (cons x lst))) '(min max))) (mapcar 'cdr (vl-remove-if-not '(lambda ( x ) (= 10 (car x))) (entget ent))) ) ) Usage: (defun c:test ( / sel ) (cond ( (not (setq sel (car (entsel))))) ( (/= "LWPOLYLINE" (cdr (assoc 0 (entget sel)))) (princ "\nObject is not an LWPolyline.") ) ( (foreach x (polybb sel) (entmake (list '(0 . "POINT") (cons 10 (trans x sel 0)))) ) ) ) (princ) ) 1 Quote
Akanezuko Posted September 19 Author Posted September 19 7 hours ago, Lee Mac said: Assuming rectangular bounding box for LWPolyline - (defun polybb ( ent ) ( (lambda ( lst ) (mapcar '(lambda ( x ) (apply 'mapcar (cons x lst))) '(min max))) (mapcar 'cdr (vl-remove-if-not '(lambda ( x ) (= 10 (car x))) (entget ent))) ) ) Usage: (defun c:test ( / sel ) (cond ( (not (setq sel (car (entsel))))) ( (/= "LWPOLYLINE" (cdr (assoc 0 (entget sel)))) (princ "\nObject is not an LWPolyline.") ) ( (foreach x (polybb sel) (entmake (list '(0 . "POINT") (cons 10 (trans x sel 0)))) ) ) ) (princ) ) Thank you @Lee Mac for the reply. The code you sent work like a bounding box but my requirement is to get four corners of a polygon. Quote
lastknownuser Posted September 19 Posted September 19 42 minutes ago, Akanezuko said: Thank you @Lee Mac for the reply. The code you sent work like a bounding box but my requirement is to get four corners of a polygon. Maybe this, by Lee Mac: https://www.lee-mac.com/minboundingbox.html Quote
SLW210 Posted September 19 Posted September 19 Maybe something like this, I am at home, but works on 2000i. I think I started this back when I first started some tutorials, probably AfraLISP or something. I just have this going to the commandline, you have provided limited information to the use of the points. ;;; Get the four corners of a rectangle. ;;; ;;; https://www.cadtutor.net/forum/topic/91208-corner-points-of-a-polygon/?do=findComment&comment=651476 ;;; ;;; By SLW210 (Steve Wilson) ;;; ;;; (defun c:GetCorners () (setq pt1 (getpoint "\nSelect first corner of rectangle: ")) (setq pt2 (getpoint pt1 "\nSelect opposite corner: ")) ;; Calculate the corners based on the input points (setq x1 (car pt1) y1 (cadr pt1) x2 (car pt2) y2 (cadr pt2)) (setq corner1 (list x1 y1) ; Bottom-left corner2 (list x2 y1) ; Bottom-right corner3 (list x2 y2) ; Top-right corner4 (list x1 y2)) ; Top-left ;; Output the corners (princ (strcat "\nCorners of the rectangle are: " (rtos (car corner1) 2 2) "," (rtos (cadr corner1) 2 2) "; " (rtos (car corner2) 2 2) "," (rtos (cadr corner2) 2 2) "; " (rtos (car corner3) 2 2) "," (rtos (cadr corner3) 2 2) "; " (rtos (car corner4) 2 2) "," (rtos (cadr corner4) 2 2))) (princ) ) Similar posts... https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/rectangle-corner-points/td-p/9501488 Quote
Lee Mac Posted September 19 Posted September 19 Here's another approach - (defun c:test ( / elv ent enx ) (cond ( (not (setq ent (car (entsel))))) ( (/= "LWPOLYLINE" (cdr (assoc 0 (setq enx (entget ent))))) (princ "\nObject is not a polyline.") ) ( t (setq elv (list (cdr (assoc 38 enx)))) (foreach x (getcorners ent) (entmake (list '(0 . "POINT") (cons 10 (trans (append x elv) ent 0)))) ) ) ) (princ) ) (defun getcorners ( ent / enx lst pnt rtn ) (setq enx (entget ent) lst (mapcar 'cdr (vl-remove-if-not '(lambda ( x ) (= 10 (car x))) enx)) ) (if (< (length lst) 3) lst (progn (setq rtn (list (cadr lst) (car lst)) lst (cddr lst) ) (while (setq pnt (car lst)) (while (and (cadr rtn) (LM:collinear-p pnt (car rtn) (cadr rtn))) (setq rtn (cdr rtn)) ) (setq rtn (cons pnt rtn) lst (cdr lst) ) ) (setq rtn (reverse rtn)) (if (and (= 1 (logand 1 (cdr (assoc 70 enx)))) (LM:collinear-p (last rtn) (car rtn) (cadr rtn)) ) (setq rtn (cdr rtn)) ) rtn ) ) ) ;; Collinear-p - Lee Mac ;; Returns T if p1,p2,p3 are collinear (defun LM:Collinear-p ( p1 p2 p3 ) ( (lambda ( a b c ) (or (equal (+ a b) c 1e-8) (equal (+ b c) a 1e-8) (equal (+ c a) b 1e-8) ) ) (distance p1 p2) (distance p2 p3) (distance p1 p3) ) ) (princ) 1 Quote
Nikon Posted September 20 Posted September 20 (edited) 15 hours ago, Lee Mac said: (defun c: test ( / elv ent enx ) You can add a point type to the code, because if PDMODE=0, then the reaction of the command is not visible... For example: (setvar 'PDMODE 35) (setvar 'PDSIZE 20) Edited September 20 by Nikon 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.